mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-23 14:40:45 +01:00
fix #571
This commit is contained in:
parent
a770591349
commit
0c8e074517
4 changed files with 204 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
|||
echo ""
|
||||
|
||||
# add bonus scripts (auto install deactivated to reduce third party repos)
|
||||
# /home/admin/91addBonus.sh
|
||||
/home/admin/91addBonus.sh
|
||||
|
||||
###### SWAP & FS
|
||||
echo ""
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
# https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_67_additional-scripts.md
|
||||
|
||||
echo ""
|
||||
echo "*** Adding: raspibolt_67_additional-scripts.md"
|
||||
echo "Creating the command lnbalance as well as lnchannels which will give you a nicer output"
|
||||
cd
|
||||
mkdir /home/admin/tmpScriptDL
|
||||
cd /home/admin/tmpScriptDL
|
||||
wget https://stadicus.github.io/RaspiBolt/resources/lnbalance
|
||||
wget https://stadicus.github.io/RaspiBolt/resources/lnchannels
|
||||
cd /home/admin/assets
|
||||
chmod +x lnbalance
|
||||
chmod +x lnchannels
|
||||
sudo cp lnchannels /usr/local/bin
|
||||
sudo cp lnbalance /usr/local/bin
|
||||
echo "OK"
|
||||
|
||||
mkdir /home/admin/tmpScriptDL
|
||||
cd /home/admin/tmpScriptDL
|
||||
echo "installing bash completion for bitcoin-cli and lncli"
|
||||
wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/bitcoin-cli.bash-completion
|
||||
wget https://raw.githubusercontent.com/lightningnetwork/lnd/master/contrib/lncli.bash-completion
|
||||
sudo cp *.bash-completion /etc/bash_completion.d/
|
||||
echo "OK - bash completion available after next login"
|
||||
echo "type \"bitcoin-cli getblockch\", press [Tab] → bitcoin-cli getblockchaininfo"
|
||||
cd
|
||||
rm -r /home/admin/tmpScriptDL
|
||||
|
||||
cd
|
91
home.admin/assets/lnbalance
Normal file
91
home.admin/assets/lnbalance
Normal file
|
@ -0,0 +1,91 @@
|
|||
#!/bin/bash
|
||||
# RaspiBolt channel balance display, by robclark56
|
||||
|
||||
# make executable & copy to
|
||||
# /usr/local/bin/lnbalance
|
||||
# current user must be able to execute bitcoin-cli and lncli
|
||||
|
||||
# Usage
|
||||
# $ lnbalance to display lnd mainnet status
|
||||
# $ lnbalance --testnet to display lnd testnet status
|
||||
# $ lnbalance litecoin to display lnd litecoin status
|
||||
|
||||
# Set default (mainnet)
|
||||
lncli='/usr/local/bin/lncli'
|
||||
lnd_pid=$(systemctl show -p MainPID lnd | awk -F"=" '{print $2}')
|
||||
chain='main'
|
||||
|
||||
# read cli args
|
||||
for i in "$@"
|
||||
do
|
||||
case $i in
|
||||
--testnet*)
|
||||
lncli="${lncli} --network=testnet"
|
||||
lnd_pid=$(systemctl show -p MainPID lnd | awk -F"=" '{print $2}')
|
||||
chain='test'
|
||||
shift # past argument=value
|
||||
;;
|
||||
*)
|
||||
lncli="/usr/local/bin/lncli --chain=$i"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# set colors
|
||||
color_red='\033[0;31m'
|
||||
color_green='\033[0;32m'
|
||||
color_yellow='\033[0;33m'
|
||||
color_gray='\033[0;37m'
|
||||
|
||||
# get LND info
|
||||
wallet_color="${color_yellow}"
|
||||
if [ "$lnd_pid" -ne "0" ]; then
|
||||
${lncli} getinfo 2>&1 | grep "Please unlock" >/dev/null
|
||||
wallet_unlocked=$?
|
||||
if [ "$wallet_unlocked" -eq 0 ] ; then
|
||||
wallet_color="${color_red}"
|
||||
ln_walletbalance="Locked"
|
||||
else
|
||||
ln_walletbalance="$(${lncli} walletbalance | jq -r '.confirmed_balance')" 2>/dev/null
|
||||
ln_channelbalance="$(${lncli} channelbalance | jq -r '.balance')" 2>/dev/null
|
||||
ln_channels_active="$(${lncli} listchannels --active_only| jq '.[] | length')" 2>/dev/null
|
||||
ln_channels_inactive="$(${lncli} listchannels --inactive_only| jq '.[] | length')" 2>/dev/null
|
||||
active_remote="$(${lncli} listchannels --active_only | jq -r '.channels |.[] | .remote_balance ' | jq -s 'add')"
|
||||
active_local="$(${lncli} listchannels --active_only | jq -r '.channels |.[] | .local_balance ' | jq -s 'add')"
|
||||
inactive_remote="$(${lncli} listchannels --inactive_only | jq -r '.channels |.[] | .remote_balance ' | jq -s 'add')"
|
||||
active_fees="$(${lncli} listchannels --active_only | jq -r '.channels |.[] | .commit_fee ' | jq -s 'add')"
|
||||
inactive_fees="$(${lncli} listchannels --inactive_only | jq -r '.channels |.[] | .commit_fee ' | jq -s 'add')"
|
||||
inactive_local="$(${lncli} listchannels --inactive_only | jq -r '.channels |.[] | .local_balance ' | jq -s 'add')"
|
||||
if [ "${active_local}" = 'null' ];then active_local=0;fi
|
||||
if [ "${active_remote}" = 'null' ];then active_remote=0;fi
|
||||
if [ "${inactive_local}" = 'null' ];then inactive_local=0;fi
|
||||
if [ "${active_fees}" = 'null' ];then active_fees=0;fi
|
||||
if [ "${inactive_fees}" = 'null' ];then inactive_fees=0;fi
|
||||
if [ "${inactive_remote}" = 'null' ];then inactive_remote=0;fi
|
||||
if [ "${ln_walletbalance}" = 'null' ];then ln_walletbalance=0;fi
|
||||
if [ "${ln_walletbalance}" = 'Locked' ];then ln_walletbalance=0;fi
|
||||
total_local=$(( ${ln_walletbalance} + ${active_local} + ${inactive_local} ))
|
||||
total_remote=$(( ${active_remote} + ${inactive_remote} ))
|
||||
total_fees=$(( ${active_fees} + ${inactive_fees} ))
|
||||
ln_channels=$(( ${ln_channels_active} + ${ln_channels_inactive} ))
|
||||
fi
|
||||
else
|
||||
wallet_color="${color_red}"
|
||||
ln_walletbalance="Not Running"
|
||||
fi
|
||||
|
||||
margin=''
|
||||
printf "
|
||||
${margin}${color_yellow}%-21s${color_gray}| ${color_yellow}Local${color_gray}| ${color_yellow}Remote${color_gray}|${color_yellow}Commitment Fees${color_gray}|
|
||||
${margin}${color_gray}%-21s|${color_green}%12s${color_gray}|%12s|%15s|
|
||||
${margin}${color_gray}%-18s%3s|${color_green}%12s${color_gray}|${color_yellow}%12s${color_gray}|${color_red}%15s${color_gray}|
|
||||
${margin}${color_gray}%-18s%3s|${color_red}%12s${color_gray}|${color_red}%12s${color_gray}|${color_red}%15s${color_gray}|
|
||||
${margin}${color_gray}%-18s%3s|%12s|%12s|${color_red}%15s${color_gray}|
|
||||
" \
|
||||
"${chain}net (sat)" \
|
||||
"Wallet" "${ln_walletbalance}" "" "" \
|
||||
"Active Channels" "${ln_channels_active}" "${active_local}" "${active_remote}" "${active_fees}" \
|
||||
"Inactive Channels" "${ln_channels_inactive}" "${inactive_local}" "${inactive_remote}" "${inactive_fees}" \
|
||||
"Total" "${ln_channels}" "${total_local}" "${total_remote}" "${total_fees}"
|
||||
|
||||
echo "$(tput -T xterm sgr0)"
|
106
home.admin/assets/lnchannels
Normal file
106
home.admin/assets/lnchannels
Normal file
|
@ -0,0 +1,106 @@
|
|||
#!/bin/bash
|
||||
# RaspiBolt channel overview display, by robclark56
|
||||
|
||||
# make executable & copy to
|
||||
# /usr/local/bin/lnchannels
|
||||
# current user must be able to execute bitcoin-cli and lncli
|
||||
|
||||
# Usage
|
||||
# $ lnchannels to display lnd mainnet channels
|
||||
# $ lnchannels --testnet to display lnd testnet channels
|
||||
# $ lnchannels litecoin to display lnd litecoin channels
|
||||
|
||||
# Set default (mainnet)
|
||||
lncli='/usr/local/bin/lncli'
|
||||
lnd_pid=$(systemctl show -p MainPID lnd | awk -F"=" '{print $2}')
|
||||
chain='main'
|
||||
|
||||
# read cli args
|
||||
for i in "$@"
|
||||
do
|
||||
case $i in
|
||||
--testnet*)
|
||||
lncli="${lncli} --network=testnet"
|
||||
lnd_pid=$(systemctl show -p MainPID lnd | awk -F"=" '{print $2}')
|
||||
chain='test'
|
||||
shift # past argument=value
|
||||
;;
|
||||
*)
|
||||
lncli="/usr/local/bin/lncli --chain=$i"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$lnd_pid" -eq "0" ]; then
|
||||
echo lnd not runnning.
|
||||
exit
|
||||
fi
|
||||
|
||||
# set colors
|
||||
color_red='\033[0;31m'
|
||||
color_green='\033[0;32m'
|
||||
color_yellow='\033[0;33m'
|
||||
color_gray='\033[0;37m'
|
||||
|
||||
# gather values
|
||||
a_active=( $(${lncli} listchannels | jq -r ' .channels[].active'))
|
||||
a_remote_pubkey=( $(${lncli} listchannels | jq -r ' .channels[].remote_pubkey'))
|
||||
a_capacity=( $(${lncli} listchannels | jq -r ' .channels[].capacity'))
|
||||
a_local_balance=( $(${lncli} listchannels | jq -r ' .channels[].local_balance'))
|
||||
a_remote_balance=( $(${lncli} listchannels | jq -r ' .channels[].remote_balance'))
|
||||
a_commit_fee=( $(${lncli} listchannels | jq -r ' .channels[].commit_fee'))
|
||||
a_channel_point=( $(${lncli} listchannels | jq -r ' .channels[].channel_point'))
|
||||
|
||||
total=${#a_active[*]}
|
||||
total_capacity=0
|
||||
total_fee=0
|
||||
total_local=0
|
||||
total_remote=0
|
||||
|
||||
#display
|
||||
printf "\n${color_yellow}%-7s%60s %11s\n" "${chain}net" 'Commit ------- Balance ---------' '--- Fee ----'
|
||||
printf "%-21s %12s %5s %12s %12s %6s %5s\n" 'Alias or Pubkey' 'Capacity' 'Fee' 'Local' 'Remote' 'Base' 'PerMil'
|
||||
horiz_line="-------------------- ------------- ------ ------------ ------------ ----- ------"
|
||||
echo $horiz_line
|
||||
for (( i=0; i<=$(( $total -1 )); i++ ));do
|
||||
addr_port=$(${lncli} getnodeinfo ${a_remote_pubkey[$i]} | jq -r .node.addresses[0].addr)
|
||||
addr=${addr_port/:/ }
|
||||
if [ ${a_active[$i]} == 'true' ]; then
|
||||
color_line=${color_gray}
|
||||
public_check=''
|
||||
else
|
||||
color_line=${color_red}
|
||||
public_check='0';
|
||||
if [ "$addr" != 'null' ]; then public_check=$(timeout 2s nc -z ${addr}; echo $?);fi
|
||||
if [ "${public_check}" == '0' ];then public_check='';else public_check='X';fi
|
||||
fi
|
||||
alias=$(${lncli} getnodeinfo ${a_remote_pubkey[$i]} | jq -r .node.alias)
|
||||
if [ "${alias}" == "" ] ; then
|
||||
alias_short=$(echo ${a_remote_pubkey[$i]} | cut -c-17)...
|
||||
else
|
||||
alias_short=$(echo ${alias} | cut -c-20)
|
||||
fi
|
||||
active_short=$(echo ${a_active[$i]} | cut -c1)
|
||||
# get fee report details
|
||||
base_fee_msat=$(${lncli} feereport | jq -r ".channel_fees[] | select(.channel_point | test(\"${a_channel_point[$i]}\")) | .base_fee_msat")
|
||||
fee_per_mil=$(${lncli} feereport | jq -r ".channel_fees[] | select(.channel_point |
|
||||
test(\"${a_channel_point[$i]}\")) | .fee_per_mil")
|
||||
# Display line
|
||||
printf "${color_line}%-21s %12s %6s %12s %12s %5s %6s\r%-21s\n" \
|
||||
"" "${a_capacity[$i]}" "${a_commit_fee[$i]}" "${a_local_balance[$i]}" \
|
||||
"${a_remote_balance[$i]}" "${base_fee_msat}" "${fee_per_mil}" "${alias_short}"
|
||||
total_capacity=$(( ${total_capacity} + ${a_capacity[$i]} ))
|
||||
total_fee=$(( ${total_fee} + ${a_commit_fee[$i]} ))
|
||||
total_local=$(( ${total_local} + ${a_local_balance[$i]} ))
|
||||
total_remote=$(( ${total_remote} + ${a_remote_balance[$i]} ))
|
||||
if [ ${#public_check} != 0 ] ; then echo " > No response from Addr:Port ${addr_port}";fi
|
||||
done
|
||||
printf "${color_yellow}%s\n" "${horiz_line}"
|
||||
printf "Totals%14s %13s %6s %12s %12s Day: %7s\n" \
|
||||
"${total} ch" "${total_capacity}" "${total_fee}" \
|
||||
"${total_local}" "${total_remote}" \
|
||||
"$(${lncli} feereport |jq -r ".day_fee_sum" )"
|
||||
printf "%74s %5s\n" 'Week: ' "$(${lncli} feereport |jq -r ".week_fee_sum" )"
|
||||
printf "%74s %5s\n" 'Month:' "$(${lncli} feereport |jq -r ".month_fee_sum" )"
|
||||
echo "$(tput -T xterm sgr0)"
|
||||
|
Loading…
Add table
Reference in a new issue