mirror of
https://github.com/Retropex/raspiblitz.git
synced 2025-05-13 03:30:49 +02:00
fix openchannels check or cln in menu (#4751)
* shellcheck format BBpayInvoice * fix openchannels check for cl * shellcheck format + fix CLN check for channels in BBcreateInvoice * nit: use paid correctly * enhance summars plugin output
This commit is contained in:
parent
fa9ff68760
commit
731aa73128
@ -20,41 +20,41 @@ source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2)
|
|||||||
source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net)
|
source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net)
|
||||||
|
|
||||||
# check if chain is in sync
|
# check if chain is in sync
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
lncommand="${netprefix}lightning-cli"
|
lncommand="${netprefix}lightning-cli"
|
||||||
BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
|
BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo | grep blocks | awk '{print $2}' | cut -d, -f1)
|
||||||
CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
|
CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
|
||||||
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
|
if [ $BLOCKHEIGHT -eq $CLHEIGHT ]; then
|
||||||
cmdChainInSync=1
|
cmdChainInSync=1
|
||||||
else
|
else
|
||||||
cmdChainInSync=0
|
cmdChainInSync=0
|
||||||
fi
|
fi
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
lncommand="${netprefix}lncli"
|
lncommand="${netprefix}lncli"
|
||||||
cmdChainInSync="$lncli_alias getinfo | grep '"synced_to_chain": true' -c"
|
cmdChainInSync="$lncli_alias getinfo | grep '"synced_to_chain": true' -c"
|
||||||
fi
|
fi
|
||||||
chainInSync=${cmdChainInSync}
|
chainInSync=${cmdChainInSync}
|
||||||
while [ "${chainInSync}" == "0" ]; do
|
while [ "${chainInSync}" == "0" ]; do
|
||||||
dialog --title "Fail: not in sync" \
|
dialog --title "Fail: not in sync" \
|
||||||
--ok-label "Try now" \
|
--ok-label "Try now" \
|
||||||
--cancel-label "Give up" \
|
--cancel-label "Give up" \
|
||||||
--pause "\n\n'$lncommand getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5
|
--pause "\n\n'$lncommand getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5
|
||||||
|
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
chainInSync=${cmdChainInSync}
|
chainInSync=${cmdChainInSync}
|
||||||
done
|
done
|
||||||
|
|
||||||
# check number of connected peers
|
# check number of connected peers
|
||||||
echo "check for open channels"
|
echo "check for open channels"
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
openChannels=$($lightningcli_alias listpeers | grep -c "CHANNELD_NORMAL")
|
openChannels=$($lightningcli_alias getinfo | jq .num_active_channels)
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c)
|
openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c)
|
||||||
fi
|
fi
|
||||||
if [ ${openChannels} -eq 0 ]; then
|
if [ ${openChannels} -eq 0 ]; then
|
||||||
echo
|
echo
|
||||||
echo "#########"
|
echo "#########"
|
||||||
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first."
|
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first."
|
||||||
echo "#########"
|
echo "#########"
|
||||||
@ -66,7 +66,7 @@ fi
|
|||||||
l1="Enter the AMOUNT IN SATOSHIS to invoice:"
|
l1="Enter the AMOUNT IN SATOSHIS to invoice:"
|
||||||
l2="1 ${network} = 100 000 000 SAT"
|
l2="1 ${network} = 100 000 000 SAT"
|
||||||
dialog --title "Request payment through Lightning" \
|
dialog --title "Request payment through Lightning" \
|
||||||
--inputbox "$l1\n$l2" 9 50 2>$_temp
|
--inputbox "$l1\n$l2" 9 50 2>$_temp
|
||||||
amount=$(cat $_temp | xargs | tr -dc '0-9')
|
amount=$(cat $_temp | xargs | tr -dc '0-9')
|
||||||
shred -u $_temp
|
shred -u $_temp
|
||||||
if [ ${#amount} -eq 0 ]; then
|
if [ ${#amount} -eq 0 ]; then
|
||||||
@ -80,12 +80,12 @@ fi
|
|||||||
# TODO let user enter a description
|
# TODO let user enter a description
|
||||||
|
|
||||||
# build command
|
# build command
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
label=$(date +%s) # seconds since 1970-01-01 00:00:00 UTC
|
label=$(date +%s) # seconds since 1970-01-01 00:00:00 UTC
|
||||||
# invoice msatoshi label description [expiry] [fallbacks] [preimage] [exposeprivatechannels] [cltv]
|
# invoice msatoshi label description [expiry] [fallbacks] [preimage] [exposeprivatechannels] [cltv]
|
||||||
command="$lightningcli_alias invoice ${amount}sat $label ''"
|
command="$lightningcli_alias invoice ${amount}sat $label ''"
|
||||||
# TODO warn about insufficient liquidity
|
# TODO warn about insufficient liquidity
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
command="$lncli_alias addinvoice ${amount}"
|
command="$lncli_alias addinvoice ${amount}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -114,16 +114,16 @@ if [ ${#error} -gt 0 ]; then
|
|||||||
echo "###############"
|
echo "###############"
|
||||||
echo "${error}"
|
echo "${error}"
|
||||||
else
|
else
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
payReq=$(echo "$result" | grep bolt11 | cut -d '"' -f4)
|
payReq=$(echo "$result" | grep bolt11 | cut -d '"' -f4)
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
rhash=$(echo "$result" | grep r_hash | cut -d '"' -f4)
|
rhash=$(echo "$result" | grep r_hash | cut -d '"' -f4)
|
||||||
payReq=$(echo "$result" | grep payment_request | cut -d '"' -f4)
|
payReq=$(echo "$result" | grep payment_request | cut -d '"' -f4)
|
||||||
fi
|
fi
|
||||||
sudo /home/admin/config.scripts/blitz.display.sh qr "${payReq}"
|
sudo /home/admin/config.scripts/blitz.display.sh qr "${payReq}"
|
||||||
|
|
||||||
if [ $(sudo dpkg-query -l | grep "ii qrencode" | wc -l) = 0 ]; then
|
if [ $(sudo dpkg-query -l | grep "ii qrencode" | wc -l) = 0 ]; then
|
||||||
sudo apt-get install qrencode -y > /dev/null
|
sudo apt-get install qrencode -y >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# raise high focus on lightning channel balance next 5min
|
# raise high focus on lightning channel balance next 5min
|
||||||
@ -141,24 +141,23 @@ else
|
|||||||
echo "${payReq}"
|
echo "${payReq}"
|
||||||
echo
|
echo
|
||||||
echo "Monitoring the Incoming Payment with:"
|
echo "Monitoring the Incoming Payment with:"
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
echo "$lightningcli_alias waitinvoice $label"
|
echo "$lightningcli_alias waitinvoice $label"
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
echo "$lncli_alias lookupinvoice ${rhash}"
|
echo "$lncli_alias lookupinvoice ${rhash}"
|
||||||
fi
|
fi
|
||||||
echo "Press x and hold to skip to menu."
|
echo "Press x and hold to skip to menu."
|
||||||
|
|
||||||
while :
|
while :; do
|
||||||
do
|
if [ $LNTYPE = cl ]; then
|
||||||
if [ $LNTYPE = cl ];then
|
|
||||||
result=$($lightningcli_alias waitinvoice $label)
|
result=$($lightningcli_alias waitinvoice $label)
|
||||||
wasPayed=$(echo $result | grep -c 'paid')
|
wasPaid=$(echo $result | grep -c 'paid')
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
result=$($lncli_alias lookupinvoice ${rhash})
|
result=$($lncli_alias lookupinvoice ${rhash})
|
||||||
wasPayed=$(echo $result | grep -c '"settled": true')
|
wasPaid=$(echo $result | grep -c '"settled": true')
|
||||||
fi
|
fi
|
||||||
if [ ${wasPayed} -gt 0 ]; then
|
if [ ${wasPaid} -gt 0 ]; then
|
||||||
echo
|
echo
|
||||||
echo $result
|
echo $result
|
||||||
echo
|
echo
|
||||||
echo "OK the Invoice was paid - returning to menu."
|
echo "OK the Invoice was paid - returning to menu."
|
||||||
@ -167,16 +166,16 @@ else
|
|||||||
sleep 2
|
sleep 2
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# wait 2 seconds for key input
|
# wait 2 seconds for key input
|
||||||
read -n 1 -t 2 keyPressed
|
read -n 1 -t 2 keyPressed
|
||||||
|
|
||||||
# check if user wants to abort session
|
# check if user wants to abort session
|
||||||
if [ "${keyPressed}" = "x" ]; then
|
if [ "${keyPressed}" = "x" ]; then
|
||||||
echo
|
echo
|
||||||
echo $result
|
echo $result
|
||||||
echo
|
echo
|
||||||
echo "Returning to menu - invoice was not payed yet."
|
echo "Returning to menu - the invoice has not been paid yet."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -186,4 +185,4 @@ else
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
echo "Press ENTER to return to main menu."
|
echo "Press ENTER to return to main menu."
|
||||||
read key
|
read key
|
||||||
|
@ -19,46 +19,46 @@ fi
|
|||||||
source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2)
|
source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2)
|
||||||
|
|
||||||
# check if chain is in sync
|
# check if chain is in sync
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
lncommand="${netprefix}lightning-cli"
|
lncommand="${netprefix}lightning-cli"
|
||||||
BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
|
BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo | grep blocks | awk '{print $2}' | cut -d, -f1)
|
||||||
CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
|
CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
|
||||||
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
|
if [ $BLOCKHEIGHT -eq $CLHEIGHT ]; then
|
||||||
cmdChainInSync=1
|
cmdChainInSync=1
|
||||||
else
|
else
|
||||||
cmdChainInSync=0
|
cmdChainInSync=0
|
||||||
fi
|
fi
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
lncommand="${netprefix}lncli"
|
lncommand="${netprefix}lncli"
|
||||||
cmdChainInSync="$lncli_alias getinfo | grep '"synced_to_chain": true' -c"
|
cmdChainInSync="$lncli_alias getinfo | grep '"synced_to_chain": true' -c"
|
||||||
fi
|
fi
|
||||||
chainInSync=${cmdChainInSync}
|
chainInSync=${cmdChainInSync}
|
||||||
while [ "${chainInSync}" == "0" ]; do
|
while [ "${chainInSync}" == "0" ]; do
|
||||||
dialog --title "Fail: not in sync" \
|
dialog --title "Fail: not in sync" \
|
||||||
--ok-label "Try now" \
|
--ok-label "Try now" \
|
||||||
--cancel-label "Give up" \
|
--cancel-label "Give up" \
|
||||||
--pause "\n\n'$lncommand getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5
|
--pause "\n\n'$lncommand getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5
|
||||||
|
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
chainInSync=${cmdChainInSync}
|
chainInSync=${cmdChainInSync}
|
||||||
done
|
done
|
||||||
|
|
||||||
# check number of connected peers
|
# check number of connected peers
|
||||||
echo "check for open channels"
|
echo "check for open channels"
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
openChannels=$($lightningcli_alias listpeers | grep -c "CHANNELD_NORMAL")
|
openChannels=$($lightningcli_alias getinfo | jq .num_active_channels)
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c)
|
openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c)
|
||||||
fi
|
fi
|
||||||
if [ ${openChannels} -eq 0 ]; then
|
if [ ${openChannels} -eq 0 ]; then
|
||||||
echo
|
echo
|
||||||
echo "#########"
|
echo "#########"
|
||||||
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first."
|
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first."
|
||||||
echo "#########"
|
echo "#########"
|
||||||
sleep 3
|
sleep 3
|
||||||
echo
|
echo
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ l1="Copy the LightningInvoice/PaymentRequest into here:"
|
|||||||
l2="Its a long string starting with '${paymentRequestStart}'"
|
l2="Its a long string starting with '${paymentRequestStart}'"
|
||||||
l3="To try it out go to: ${testSite}"
|
l3="To try it out go to: ${testSite}"
|
||||||
dialog --title "Pay through the Lightning Network" \
|
dialog --title "Pay through the Lightning Network" \
|
||||||
--inputbox "$l1\n$l2\n$l3" 10 70 2>$_temp
|
--inputbox "$l1\n$l2\n$l3" 10 70 2>$_temp
|
||||||
invoice=$(cat $_temp | xargs)
|
invoice=$(cat $_temp | xargs)
|
||||||
shred -u $_temp
|
shred -u $_temp
|
||||||
if [ ${#invoice} -eq 0 ]; then
|
if [ ${#invoice} -eq 0 ]; then
|
||||||
@ -95,10 +95,10 @@ fi
|
|||||||
# TODO: maybe try/show the decoded info first by using https://api.lightning.community/#decodepayreq
|
# TODO: maybe try/show the decoded info first by using https://api.lightning.community/#decodepayreq
|
||||||
|
|
||||||
# build command
|
# build command
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
# pay bolt11 [msatoshi] [label] [riskfactor] [maxfeepercent] [retry_for] [maxdelay] [exemptfee]
|
# pay bolt11 [msatoshi] [label] [riskfactor] [maxfeepercent] [retry_for] [maxdelay] [exemptfee]
|
||||||
command="$lightningcli_alias pay ${invoice}"
|
command="$lightningcli_alias pay ${invoice}"
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
command="$lncli_alias sendpayment --force --pay_req=${invoice}"
|
command="$lncli_alias sendpayment --force --pay_req=${invoice}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ echo "Pay Invoice / Payment Request"
|
|||||||
echo "This script is an example using lightning in the command line."
|
echo "This script is an example using lightning in the command line."
|
||||||
echo "It is not optimized for performance or error handling."
|
echo "It is not optimized for performance or error handling."
|
||||||
echo "************************************************************"
|
echo "************************************************************"
|
||||||
echo
|
echo
|
||||||
echo "COMMAND LINE: "
|
echo "COMMAND LINE: "
|
||||||
echo $command
|
echo $command
|
||||||
echo
|
echo
|
||||||
@ -125,9 +125,9 @@ error=$(cat ${_error})
|
|||||||
#echo "result(${result})"
|
#echo "result(${result})"
|
||||||
#echo "error(${error})"
|
#echo "error(${error})"
|
||||||
|
|
||||||
if [ $LNTYPE = cl ];then
|
if [ $LNTYPE = cl ]; then
|
||||||
resultIsError=$(echo "${result}" | grep -c '"code":')
|
resultIsError=$(echo "${result}" | grep -c '"code":')
|
||||||
elif [ $LNTYPE = lnd ];then
|
elif [ $LNTYPE = lnd ]; then
|
||||||
resultIsError=$(echo "${result}" | grep -c "payment_error")
|
resultIsError=$(echo "${result}" | grep -c "payment_error")
|
||||||
fi
|
fi
|
||||||
if [ ${resultIsError} -gt 0 ]; then
|
if [ ${resultIsError} -gt 0 ]; then
|
||||||
|
@ -34,9 +34,9 @@ fi
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
echo "# Running:"
|
echo "# Running:"
|
||||||
echo "${netprefix}lightning-cli -H summars summars-columns=IN_SATS,OUT_SATS,GRAPH_SATS,ALIAS summars-sort-by=IN_SATS"
|
echo "${netprefix}lightning-cli -H summars summars-columns=IN_SATS,OUT_SATS,GRAPH_SATS,ALIAS,FLAG,BASE,PPM,UPTIME,HTLCS,STATE summars-sort-by=-IN_SATS"
|
||||||
echo
|
echo
|
||||||
$lightningcli_alias -H summars summars-columns=IN_SATS,OUT_SATS,GRAPH_SATS,ALIAS summars-sort-by=IN_SATS
|
$lightningcli_alias -H summars summars-columns=IN_SATS,OUT_SATS,GRAPH_SATS,ALIAS,FLAG,BASE,PPM,UPTIME,HTLCS,STATE summars-sort-by=-IN_SATS
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [ "$(echo "$@" | grep -c "runonce")" -gt 0 ]; then
|
if [ "$(echo "$@" | grep -c "runonce")" -gt 0 ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user