mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 22:58:43 +01:00
cln: create and pay invoice from menu
This commit is contained in:
parent
e6b223ea59
commit
44cf39a505
3 changed files with 124 additions and 29 deletions
|
@ -26,8 +26,8 @@ OPTIONS=()
|
||||||
OPTIONS+=(FUNDING "Fund your C-Lightning Wallet")
|
OPTIONS+=(FUNDING "Fund your C-Lightning Wallet")
|
||||||
OPTIONS+=(PEERING "Connect to a Peer")
|
OPTIONS+=(PEERING "Connect to a Peer")
|
||||||
OPTIONS+=(CHANNEL "Open a Channel with Peer")
|
OPTIONS+=(CHANNEL "Open a Channel with Peer")
|
||||||
#TODO OPTIONS+=(SEND "Pay an Invoice/PaymentRequest")
|
OPTIONS+=(SEND "Pay an Invoice/PaymentRequest")
|
||||||
#TODO OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest")
|
OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest")
|
||||||
|
|
||||||
if [ "${chain}" = "main" ]; then
|
if [ "${chain}" = "main" ]; then
|
||||||
#TODO OPTIONS+=(lnbalance "Detailed Wallet Balances")
|
#TODO OPTIONS+=(lnbalance "Detailed Wallet Balances")
|
||||||
|
@ -98,10 +98,10 @@ case $CHOICE in
|
||||||
/home/admin/BBopenChannel.sh cln $NETWORK
|
/home/admin/BBopenChannel.sh cln $NETWORK
|
||||||
;;
|
;;
|
||||||
SEND)
|
SEND)
|
||||||
/home/admin/BBpayInvoice.sh
|
/home/admin/BBpayInvoice.sh cln $NETWORK
|
||||||
;;
|
;;
|
||||||
RECEIVE)
|
RECEIVE)
|
||||||
/home/admin/BBcreateInvoice.sh
|
/home/admin/BBcreateInvoice.sh cln $NETWORK
|
||||||
;;
|
;;
|
||||||
NAME)
|
NAME)
|
||||||
sudo /home/admin/config.scripts/lnd.setname.sh
|
sudo /home/admin/config.scripts/lnd.setname.sh
|
||||||
|
|
|
@ -14,16 +14,50 @@ if [ ${#chain} -eq 0 ]; then
|
||||||
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# LNTYPE is lnd | cln
|
||||||
|
if [ $# -gt 0 ];then
|
||||||
|
LNTYPE=$1
|
||||||
|
else
|
||||||
|
LNTYPE=lnd
|
||||||
|
fi
|
||||||
|
# CHAIN is signet | testnet | mainnet
|
||||||
|
if [ $# -gt 1 ];then
|
||||||
|
CHAIN=$2
|
||||||
|
chain=${CHAIN::-3}
|
||||||
|
else
|
||||||
|
CHAIN=${chain}net
|
||||||
|
fi
|
||||||
|
if [ ${chain} = test ];then
|
||||||
|
netprefix="t"
|
||||||
|
L1rpcportmod=1
|
||||||
|
L2rpcportmod=1
|
||||||
|
elif [ ${chain} = sig ];then
|
||||||
|
netprefix="s"
|
||||||
|
L1rpcportmod=3
|
||||||
|
L2rpcportmod=3
|
||||||
|
elif [ ${chain} = main ];then
|
||||||
|
netprefix=""
|
||||||
|
L1rpcportmod=""
|
||||||
|
L2rpcportmod=0
|
||||||
|
fi
|
||||||
|
lncli_alias="sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009"
|
||||||
|
bitcoincli_alias="/usr/local/bin/${network}-cli -rpcport=${L1rpcportmod}8332"
|
||||||
|
lightningcli_alias="sudo -u bitcoin /usr/local/bin/lightning-cli --conf=/home/bitcoin/.lightning/${netprefix}config"
|
||||||
|
shopt -s expand_aliases
|
||||||
|
alias lncli_alias="$lncli_alias"
|
||||||
|
alias bitcoincli_alias="$bitcoincli_alias"
|
||||||
|
alias lightningcli_alias="$lightningcli_alias"
|
||||||
|
|
||||||
# Check if ready (chain in sync and channels open)
|
# Check if ready (chain in sync and channels open)
|
||||||
./XXchainInSync.sh $network $chain
|
./XXchainInSync.sh $network $chain $LNTYPE
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# let user enter the invoice
|
# let user enter the invoice
|
||||||
l1="Enter the AMOUNT IN SATOSHI of the 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 "Pay thru Lightning Network" \
|
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
|
||||||
|
@ -38,23 +72,30 @@ fi
|
||||||
# TODO let user enter a description
|
# TODO let user enter a description
|
||||||
|
|
||||||
# build command
|
# build command
|
||||||
command="lncli --chain=${network} --network=${chain}net addinvoice ${amount}"
|
if [ $LNTYPE = cln ];then
|
||||||
|
label=$(date +%s) # seconds since 1970-01-01 00:00:00 UTC
|
||||||
|
# invoice msatoshi label description [expiry] [fallbacks] [preimage] [exposeprivatechannels] [cltv]
|
||||||
|
command="$lightningcli_alias invoice ${amount}sat $label ''"
|
||||||
|
# TODO warn about insufficient liquidity
|
||||||
|
elif [ $LNTYPE = lnd ];then
|
||||||
|
command="$lncli_alias addinvoice ${amount}"
|
||||||
|
fi
|
||||||
|
|
||||||
# info output
|
# info output
|
||||||
clear
|
clear
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo "Create Invoice / Payment Request"
|
echo "Create Invoice / Payment Request"
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo ""
|
echo
|
||||||
echo "COMMAND LINE: "
|
echo "COMMAND LINE: "
|
||||||
echo $command
|
echo $command
|
||||||
echo ""
|
echo
|
||||||
echo "RESULT:"
|
echo "RESULT:"
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# execute command
|
# execute command
|
||||||
result=$($command 2>$_error)
|
result=$($command 2>$_error)
|
||||||
error=`cat ${_error} 2>/dev/null`
|
error=$(cat ${_error} 2>/dev/null)
|
||||||
|
|
||||||
#echo "result(${result})"
|
#echo "result(${result})"
|
||||||
#echo "error(${error})"
|
#echo "error(${error})"
|
||||||
|
@ -65,9 +106,12 @@ if [ ${#error} -gt 0 ]; then
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
echo "${error}"
|
echo "${error}"
|
||||||
else
|
else
|
||||||
|
if [ $LNTYPE = cln ];then
|
||||||
|
payReq=$(echo "$result" | grep bolt11 | cut -d '"' -f4)
|
||||||
|
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
|
||||||
/home/admin/config.scripts/blitz.display.sh qr "${payReq}"
|
/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
|
||||||
|
@ -86,19 +130,27 @@ else
|
||||||
echo "${payReq}"
|
echo "${payReq}"
|
||||||
echo
|
echo
|
||||||
echo "Monitoring the Incoming Payment with:"
|
echo "Monitoring the Incoming Payment with:"
|
||||||
echo "lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash}"
|
if [ $LNTYPE = cln ];then
|
||||||
|
echo "$lightningcli_alias waitinvoice $label"
|
||||||
|
elif [ $LNTYPE = lnd ];then
|
||||||
|
echo "$lncli_alias lookupinvoice ${rhash}"
|
||||||
|
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 = cln ];then
|
||||||
result=$(lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash})
|
result=$($lightningcli_alias waitinvoice $label)
|
||||||
|
wasPayed=$(echo $result | grep -c 'paid')
|
||||||
|
elif [ $LNTYPE = lnd ];then
|
||||||
|
result=$($lncli_alias lookupinvoice ${rhash})
|
||||||
wasPayed=$(echo $result | grep -c '"settled": true')
|
wasPayed=$(echo $result | grep -c '"settled": true')
|
||||||
|
fi
|
||||||
if [ ${wasPayed} -gt 0 ]; then
|
if [ ${wasPayed} -gt 0 ]; then
|
||||||
echo
|
echo
|
||||||
echo $result
|
echo $result
|
||||||
echo
|
echo
|
||||||
echo "Returning to menu - OK Invoice payed."
|
echo "OK the Invoice was paid - returning to menu."
|
||||||
/home/admin/config.scripts/blitz.display.sh hide
|
/home/admin/config.scripts/blitz.display.sh hide
|
||||||
/home/admin/config.scripts/blitz.display.sh image /home/admin/raspiblitz/pictures/ok.png
|
/home/admin/config.scripts/blitz.display.sh image /home/admin/raspiblitz/pictures/ok.png
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
|
@ -14,8 +14,42 @@ if [ ${#chain} -eq 0 ]; then
|
||||||
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# LNTYPE is lnd | cln
|
||||||
|
if [ $# -gt 0 ];then
|
||||||
|
LNTYPE=$1
|
||||||
|
else
|
||||||
|
LNTYPE=lnd
|
||||||
|
fi
|
||||||
|
# CHAIN is signet | testnet | mainnet
|
||||||
|
if [ $# -gt 1 ];then
|
||||||
|
CHAIN=$2
|
||||||
|
chain=${CHAIN::-3}
|
||||||
|
else
|
||||||
|
CHAIN=${chain}net
|
||||||
|
fi
|
||||||
|
if [ ${chain} = test ];then
|
||||||
|
netprefix="t"
|
||||||
|
L1rpcportmod=1
|
||||||
|
L2rpcportmod=1
|
||||||
|
elif [ ${chain} = sig ];then
|
||||||
|
netprefix="s"
|
||||||
|
L1rpcportmod=3
|
||||||
|
L2rpcportmod=3
|
||||||
|
elif [ ${chain} = main ];then
|
||||||
|
netprefix=""
|
||||||
|
L1rpcportmod=""
|
||||||
|
L2rpcportmod=0
|
||||||
|
fi
|
||||||
|
lncli_alias="sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009"
|
||||||
|
bitcoincli_alias="/usr/local/bin/${network}-cli -rpcport=${L1rpcportmod}8332"
|
||||||
|
lightningcli_alias="sudo -u bitcoin /usr/local/bin/lightning-cli --conf=/home/bitcoin/.lightning/${netprefix}config"
|
||||||
|
shopt -s expand_aliases
|
||||||
|
alias lncli_alias="$lncli_alias"
|
||||||
|
alias bitcoincli_alias="$bitcoincli_alias"
|
||||||
|
alias lightningcli_alias="$lightningcli_alias"
|
||||||
|
|
||||||
# Check if ready (chain in sync and channels open)
|
# Check if ready (chain in sync and channels open)
|
||||||
./XXchainInSync.sh $network $chain
|
./XXchainInSync.sh $network $chain $LNTYPE
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -36,7 +70,7 @@ if [ "${network}" = "bitcoin" ]; then
|
||||||
if [ "${chain}" = "main" ]; then
|
if [ "${chain}" = "main" ]; then
|
||||||
testSite="https://satoshis.place"
|
testSite="https://satoshis.place"
|
||||||
else
|
else
|
||||||
testSite="https://testnet.satoshis.place"
|
testSite="https://starblocks.acinq.co/"
|
||||||
fi
|
fi
|
||||||
elif [ "${network}" = "litecoin" ]; then
|
elif [ "${network}" = "litecoin" ]; then
|
||||||
testSite="https://millionlitecoinhomepage.net"
|
testSite="https://millionlitecoinhomepage.net"
|
||||||
|
@ -46,7 +80,7 @@ fi
|
||||||
l1="Copy the LightningInvoice/PaymentRequest into here:"
|
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 thru 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
|
||||||
|
@ -61,7 +95,12 @@ 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
|
||||||
command="lncli --chain=${network} --network=${chain}net sendpayment --force --pay_req=${invoice}"
|
if [ $LNTYPE = cln ];then
|
||||||
|
# pay bolt11 [msatoshi] [label] [riskfactor] [maxfeepercent] [retry_for] [maxdelay] [exemptfee]
|
||||||
|
command="$lightningcli_alias pay ${invoice}"
|
||||||
|
elif [ $LNTYPE = lnd ];then
|
||||||
|
command="$lncli_alias sendpayment --force --pay_req=${invoice}"
|
||||||
|
fi
|
||||||
|
|
||||||
# info output
|
# info output
|
||||||
clear
|
clear
|
||||||
|
@ -70,20 +109,24 @@ echo "Pay Invoice / Payment Request"
|
||||||
echo "This script is as an example how to use the lncli interface."
|
echo "This script is as an example how to use the lncli interface."
|
||||||
echo "Its not optimized for performance or error handling."
|
echo "Its not optimized for performance or error handling."
|
||||||
echo "************************************************************"
|
echo "************************************************************"
|
||||||
echo ""
|
echo
|
||||||
echo "COMMAND LINE: "
|
echo "COMMAND LINE: "
|
||||||
echo $command
|
echo $command
|
||||||
echo ""
|
echo
|
||||||
echo "RESULT (may wait in case of timeout):"
|
echo "RESULT (may wait in case of timeout):"
|
||||||
|
|
||||||
# execute command
|
# execute command
|
||||||
result=$($command 2>$_error)
|
result=$($command 2>$_error)
|
||||||
error=`cat ${_error}`
|
error=$(cat ${_error})
|
||||||
|
|
||||||
#echo "result(${result})"
|
#echo "result(${result})"
|
||||||
#echo "error(${error})"
|
#echo "error(${error})"
|
||||||
|
|
||||||
resultIsError=$(echo "${result}" | grep -c "payment_error")
|
if [ $LNTYPE = cln ];then
|
||||||
|
resultIsError=$(echo "${result}" | grep -c '"code":')
|
||||||
|
elif [ $LNTYPE = lnd ];then
|
||||||
|
resultIsError=$(echo "${result}" | grep -c "payment_error")
|
||||||
|
fi
|
||||||
if [ ${resultIsError} -gt 0 ]; then
|
if [ ${resultIsError} -gt 0 ]; then
|
||||||
error="${result}"
|
error="${result}"
|
||||||
fi
|
fi
|
||||||
|
@ -99,8 +142,8 @@ else
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo "WIN"
|
echo "WIN"
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo "It worked :) - check out the service you were paying."
|
echo "It worked :) - check the service you were paying."
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo
|
||||||
echo "Press ENTER to return to main menu."
|
echo "Press ENTER to return to main menu."
|
||||||
read key
|
read key
|
||||||
|
|
Loading…
Add table
Reference in a new issue