From 5e225ef94e79f7e3908e8d1d7b432cba4a239d31 Mon Sep 17 00:00:00 2001 From: richdbtc Date: Sun, 26 Jan 2020 02:20:01 +0000 Subject: [PATCH 1/3] Added lightning forwarding event report --- home.admin/00mainMenu.sh | 11 ++++- home.admin/91addBonus.sh | 3 +- home.admin/XXlnfwdreport.sh | 38 ++++++++++++++++ home.admin/assets/lnfwdreport.sh | 74 ++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100755 home.admin/XXlnfwdreport.sh create mode 100755 home.admin/assets/lnfwdreport.sh diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index 2afedd987..cef818307 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -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 \ No newline at end of file +esac diff --git a/home.admin/91addBonus.sh b/home.admin/91addBonus.sh index 0f43dab73..c7ee73e0d 100755 --- a/home.admin/91addBonus.sh +++ b/home.admin/91addBonus.sh @@ -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 \ No newline at end of file +cd diff --git a/home.admin/XXlnfwdreport.sh b/home.admin/XXlnfwdreport.sh new file mode 100755 index 000000000..cd15f1123 --- /dev/null +++ b/home.admin/XXlnfwdreport.sh @@ -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 @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 "" diff --git a/home.admin/assets/lnfwdreport.sh b/home.admin/assets/lnfwdreport.sh new file mode 100755 index 000000000..bd58b6a5a --- /dev/null +++ b/home.admin/assets/lnfwdreport.sh @@ -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" From 99210ff3fca8bf352ee64e0e9f9c4f0513e68725 Mon Sep 17 00:00:00 2001 From: richdbtc <54877119+richdbtc@users.noreply.github.com> Date: Sat, 25 Jan 2020 20:30:27 -0600 Subject: [PATCH 2/3] Make forwarding event report script executable --- home.admin/91addBonus.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/home.admin/91addBonus.sh b/home.admin/91addBonus.sh index c7ee73e0d..e90948faf 100755 --- a/home.admin/91addBonus.sh +++ b/home.admin/91addBonus.sh @@ -5,6 +5,7 @@ cd cd /home/admin/assets chmod +x lnbalance.sh chmod +x lnchannels.sh +chmod +x lnfwdreport.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 From f93652cdc899daf8ccfa84e2b9ff8664578a77e0 Mon Sep 17 00:00:00 2001 From: richdbtc Date: Mon, 27 Jan 2020 01:05:53 +0000 Subject: [PATCH 3/3] Adding bsdmainutils for armbian --- build_sdcard.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_sdcard.sh b/build_sdcard.sh index 446968473..751214589 100644 --- a/build_sdcard.sh +++ b/build_sdcard.sh @@ -258,7 +258,7 @@ echo "*** SOFTWARE UPDATE ***" # based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_20_pi.md#software-update # installs like on RaspiBolt -sudo apt-get install -y htop git curl bash-completion vim jq dphys-swapfile +sudo apt-get install -y htop git curl bash-completion vim jq dphys-swapfile bsdmainutils # installs bandwidth monitoring for future statistics sudo apt-get install -y vnstat @@ -738,4 +738,4 @@ if [ "${baseImage}" != "dietpi" ]; then cd /home/admin/LCD-show/ sudo apt-mark hold raspberrypi-bootloader sudo ./LCD35-show -fi \ No newline at end of file +fi