cln: add SUMMARY option with plugin

This commit is contained in:
openoms 2021-06-11 10:33:12 +01:00
parent 869ee5f61d
commit 27cfa491bd
No known key found for this signature in database
GPG key ID: 5BFB77609B081B65
2 changed files with 52 additions and 35 deletions

View file

@ -30,27 +30,19 @@ OPTIONS+=(PEERING "Connect to a Peer")
OPTIONS+=(CHANNEL "Open a Channel with Peer")
OPTIONS+=(SEND "Pay an Invoice/PaymentRequest")
OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest")
if [ "${chain}" = "main" ]; then
#TODO OPTIONS+=(lnbalance "Detailed Wallet Balances")
#TODO OPTIONS+=(lnchannels "Lightning Channel List")
#TODO OPTIONS+=(lnfwdreport "Lightning Forwarding Events Report")
HEIGHT=$((HEIGHT+3))
CHOICE_HEIGHT=$((CHOICE_HEIGHT+3))
fi
OPTIONS+=(SUMMARY "Information about this node")
#TODO OPTIONS+=(NAME "Change Name/Alias of Node")
ln_getInfo=$($lightningcli_alias getinfo 2>/dev/null)
ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null
cln_num_inactive_channels="$(echo "${ln_getInfo}" | jq -r '.num_inactive_channels')" 2>/dev/null
openChannels=$((ln_channels_online+cln_num_inactive_channels))
if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then
OPTIONS+=(CLOSEALL "Close all open Channels")
HEIGHT=$((HEIGHT+1))
CHOICE_HEIGHT=$((CHOICE_HEIGHT+1))
fi
if [ ${#LNdefault} -gt 0 ]&&[ $LNdefault = lnd ];then
OPTIONS+=(SWITCHLN "Use C-lightning as default")
HEIGHT=$((HEIGHT+1))
@ -70,31 +62,8 @@ CHOICE=$(dialog --clear \
2>&1 >/dev/tty)
case $CHOICE in
lnbalance)
clear
echo "*** YOUR SATOSHI BALANCES ***"
/home/admin/config.scripts/lnd.balance.sh ${network}
echo "Press ENTER to return to main menu."
read key
;;
lnchannels)
clear
echo "*** YOUR LIGHTNING CHANNELS ***"
echo ""
echo "Capacity -> total sats in the channel (their side + your side)"
echo "Commit-Fee -> the fee that's charged if either side of the channel closes"
echo "Balance-Local -> sats on your side of the channel (outbound liquidity)"
echo "Balance-Remote -> sats on their side of the channel (inbound liquidity)"
echo "Fee-Base -> fixed fee (in millisatoshis) per forwarding on channel"
echo "Fee-PerMil -> amount based fee (millisatoshis per 1 satoshi) on forwarding"
/home/admin/config.scripts/lnd.channels.sh ${network}
echo "Press ENTER to return to main menu."
read key
;;
lnfwdreport)
/home/admin/config.scripts/lnd.fwdreport.sh -menu
echo "Press ENTER to return to main menu."
read key
SUMMARY)
/home/admin/config.scripts/cln.summary.sh $NETWORK
;;
PEERING)
/home/admin/BBconnectPeer.sh cln $NETWORK

View file

@ -0,0 +1,48 @@
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ];then
echo
echo "Install and show the output if the summay plugin for C-lightning"
echo "Usage:"
echo "cln.summary.sh [testnet|mainnet|signet] [runonce]"
echo
exit 1
fi
source <(/home/admin/config.scripts/network.aliases.sh getvars cln $1)
shopt -s expand_aliases
alias bitcoincli_alias="$bitcoincli_alias"
alias lncli_alias="$lncli_alias"
alias lightningcli_alias="$lightningcli_alias"
if [ ! -f "/home/bitcoin/plugins/summary/summary.py" ]; then
cd /home/bitcoin || exit 1
sudo -u bitcoin git clone https://github.com/lightningd/plugins.git
fi
if [ $(lightningcli_alias | grep -c "summary") -eq 0 ];then
echo "# Starting the summary plugin"
# https://github.com/ElementsProject/lightning/tree/master/contrib/pylightning
sudo -u bitcoin pip install pylightning 1>/dev/null
# https://github.com/lightningd/plugins#dynamic-plugin-initialization
sudo -u bitcoin pip install -r /home/bitcoin/plugins/summary/requirements.txt 1>/dev/null
lightningcli_alias plugin start -H /home/bitcoin/plugins/summary/summary.py 1>/dev/null
fi
echo
echo "Node URI:"
ln_getinfo=$(lightningcli_alias -H getinfo 2>/dev/null)
pubkey=$(echo "$ln_getinfo" | grep "id=" | cut -d= -f2)
toraddress=$(echo "$ln_getinfo" | grep ".onion" | cut -d= -f2)
port=$(echo "$ln_getinfo" | grep "port" | tail -n1 | cut -d= -f2)
echo "${pubkey}@${toraddress}:${port}"
echo
echo "# Running:"
echo "${netprefix}lightning-cli -H summary"
echo
lightningcli_alias -H summary
echo
if [ "$(echo "$@" | grep -c "runonce")" -gt 0 ];then
lightningcli_alias plugin stop -H /home/bitcoin/plugins/summary/summary.py
fi