Added lightning forwarding event report

This commit is contained in:
richdbtc 2020-01-26 02:20:01 +00:00
parent dd7eca9e91
commit 5e225ef94e
4 changed files with 123 additions and 3 deletions

View file

@ -57,7 +57,8 @@ fi
# dont offer lnbalance/lnchannels on testnet
if [ "${chain}" = "main" ]; then
OPTIONS+=(lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
lnchannels "Lightning Channel List" \
lnfwdreport "Lightning Forwarding Events Report")
fi
# Depending Options
@ -121,6 +122,12 @@ case $CHOICE in
read key
./00mainMenu.sh
;;
lnfwdreport)
./XXlnfwdreport.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
CONNECT)
./BBconnectPeer.sh
echo "Press ENTER to return to main menu."
@ -230,4 +237,4 @@ case $CHOICE in
./00mainMenu.sh
exit 0
;;
esac
esac

View file

@ -7,6 +7,7 @@ chmod +x lnbalance.sh
chmod +x lnchannels.sh
sudo cp lnbalance.sh /usr/local/bin/lnbalance
sudo cp lnchannels.sh /usr/local/bin/lnchannels
sudo cp lnfwdreport.sh /usr/local/bin/lnfwdreport
echo "OK"
mkdir /home/admin/tmpScriptDL
@ -19,4 +20,4 @@ echo "OK - bash completion available after next login"
echo "type \"bitcoin-cli getblockch\", press [Tab] → bitcoin-cli getblockchaininfo"
rm -r /home/admin/tmpScriptDL
cd
cd

38
home.admin/XXlnfwdreport.sh Executable file
View file

@ -0,0 +1,38 @@
#!/bin/bash
_temp="./download/dialog.$$"
_error="./.error.out"
# load raspiblitz config data (with backup from old config)
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
if [ ${#network} -eq 0 ]; then network=`cat .network`; fi
if [ ${#network} -eq 0 ]; then network="bitcoin"; fi
if [ ${#chain} -eq 0 ]; then
echo "gathering chain info ... please wait"
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
fi
# let user enter a <pubkey>@host
l1="Enter the number of days to query:"
l2="e.g. '7' will query the last 7 days"
dialog --title "Create a forwarding event report" \
--backtitle "Lightning ( ${network} | ${chain} )" \
--inputbox "$l1\n$l2" 10 60 7 2>$_temp
_input=$(cat $_temp | xargs )
shred $_temp
if [ ${#_input} -eq 0 ]; then
exit 1
fi
# build command
command="lnfwdreport -n ${chain}net -c ${network} -- ${_input}"
clear
echo "Generating report..."
# execute command
result=$($command 2>$_error)
echo ""
echo ""
echo "$result"
echo ""

View file

@ -0,0 +1,74 @@
#!/bin/bash
network=mainnet
chain=bitcoin
if [ $# -gt 1 ]; then
while [ -n "$1" ]; do # while loop starts
case "$1" in
-c) chain=$2
shift
;;
-n)
network="$2"
shift
;;
--)
shift # The double dash makes them parameters
break
;;
*) echo "Option $1 not recognized" ;;
esac
shift
done
fi
days=${1:-1}
start_date=$(date -d "$date -$days days" +%s)
declare -A pubKeyAliasLookup
while IFS= read -r pubKey
do
alias=$(lncli --network $network --chain $chain getnodeinfo $pubKey | jq '.node.alias')
alias=${alias:1:-1}
pubKeyAliasLookup[$pubKey]=$alias
# echo $pubKey : ${pubKeyAliasLookup[$pubKey]}
done < <(lncli --network $network --chain $chain listpeers | jq '.peers[].pub_key' | tr -d '"')
declare -A channelIdPubKeyLookup
while IFS=, read -r remotePubKey channelId
do
channelIdPubKeyLookup[$channelId]=$remotePubKey
done < <(lncli --network $network --chain $chain listchannels \
| jq --raw-output '.channels[] | [.remote_pubkey,.chan_id] | @csv' \
| tr -d '"')
OUTPUT="Date,Channel In,Channel Out,Amount,Fee
----------------,----------,-----------,------,---"
declare -i index_offset=0
while :
do
events=$(lncli --network $network --chain $chain fwdinghistory --start_time $start_date --index_offset $index_offset \
| jq -r '(([.last_offset_index, (.forwarding_events | length)]) | @csv),
(.forwarding_events[]
| [(.timestamp | tonumber | strftime("%a %d %h %H:%M")), .chan_id_in, .chan_id_out, .amt_out, .fee]
| @csv)' \
| tr -d '"')
IFS=, read last_offset_index event_count <<< "$events"
while IFS=, read eventDate channelIdIn channelIdOut amountIn fee
do
channelInPubKey=${channelIdPubKeyLookup[$channelIdIn]}
channelOutPubKey=${channelIdPubKeyLookup[$channelIdOut]}
OUTPUT="${OUTPUT}
${eventDate},${pubKeyAliasLookup[$channelInPubKey]},${pubKeyAliasLookup[$channelOutPubKey]},$amountIn,$fee"
done < <(tail -n +2 <<< $events)
if [ $event_count -lt 100 ]; then break; fi
index_offset=$last_offset_index
done
column -t -s',' <<< "$OUTPUT"