raspiblitz/home.admin/BBcreateInvoice.sh

120 lines
3 KiB
Bash
Raw Normal View History

2018-08-09 14:58:44 +02:00
#!/bin/bash
_temp="./download/dialog.$$"
_error="./.error.out"
2018-10-20 11:07:20 +02:00
sudo chmod 7777 ${_error}
2018-08-09 14:58:44 +02:00
2018-12-05 16:19:06 +01:00
# load raspiblitz config data (with backup from old config)
2019-02-02 23:49:04 +01:00
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
2018-12-05 16:19:06 +01:00
if [ ${#network} -eq 0 ]; then network=`cat .network`; fi
if [ ${#network} -eq 0 ]; then network="bitcoin"; fi
2018-12-05 16:19:06 +01:00
if [ ${#chain} -eq 0 ]; then
echo "gathering chain info ... please wait"
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
fi
2018-08-09 14:58:44 +02:00
# Check if ready (chain in sync and channels open)
./XXchainInSync.sh $network $chain
if [ $? != 0 ]; then
2018-08-09 14:58:44 +02:00
exit 1
fi
# let user enter the invoice
l1="Enter the AMOUNT IN SATOSHI of the invoice:"
l2="1 ${network} = 100 000 000 SAT"
dialog --title "Pay thru Lightning Network" \
2018-08-09 15:06:06 +02:00
--inputbox "$l1\n$l2" 9 50 2>$_temp
2018-08-09 14:58:44 +02:00
amount=$(cat $_temp | xargs | tr -dc '0-9')
shred $_temp
if [ ${#amount} -eq 0 ]; then
echo "FAIL - not a valid input (${amount})"
exit 1
fi
# TODO let user enter a description
2018-08-09 14:58:44 +02:00
# build command
2018-12-05 16:19:06 +01:00
command="lncli --chain=${network} --network=${chain}net addinvoice ${amount}"
2018-08-09 14:58:44 +02:00
# info output
clear
echo "******************************"
echo "Create Invoice / Payment Request"
echo "******************************"
echo ""
echo "COMMAND LINE: "
echo $command
echo ""
echo "RESULT:"
2018-08-09 15:08:39 +02:00
sleep 2
2018-08-09 14:58:44 +02:00
# execute command
result=$($command 2>$_error)
error=`cat ${_error}`
#echo "result(${result})"
#echo "error(${error})"
if [ ${#error} -gt 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "${error}"
else
2018-08-09 15:06:54 +02:00
rhash=$(echo "$result" | grep r_hash | cut -d '"' -f4)
payReq=$(echo "$result" | grep pay_req | cut -d '"' -f4)
2020-01-25 00:04:02 +01:00
/home/admin/config.scripts/blitz.lcd.sh qr "${payReq}"
if [ $(sudo dpkg-query -l | grep "ii qrencode" | wc -l) = 0 ]; then
sudo apt-get install qrencode -y > /dev/null
fi
echo
echo "********************"
echo "Here is your invoice"
echo "********************"
echo
2020-01-25 00:04:02 +01:00
qrencode -t ANSI256 "${payReq}"
2019-04-04 04:57:57 +01:00
echo
2018-08-09 15:06:06 +02:00
echo "Give this Invoice/PaymentRequest to someone to pay it:"
echo
echo "${payReq}"
echo
2019-07-31 14:38:38 +01:00
echo "Monitoring the Incoming Payment with:"
2019-04-04 04:57:57 +01:00
echo "lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash}"
echo "Press x and hold to skip to menu."
2018-08-09 15:06:06 +02:00
2019-04-04 04:57:57 +01:00
while :
do
2019-04-04 04:57:57 +01:00
result=$(lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash})
2019-04-04 05:03:03 +01:00
wasPayed=$(echo $result | grep -c '"settled": true')
if [ ${wasPayed} -gt 0 ]; then
echo
echo $result
echo
echo "Returning to menu - OK Invoice payed."
2020-01-25 00:04:02 +01:00
/home/admin/config.scripts/blitz.lcd.sh hide
/home/admin/config.scripts/blitz.lcd.sh image /home/admin/raspiblitz/pictures/ok.png
2019-04-04 05:16:54 +01:00
sleep 2
2019-04-04 05:03:03 +01:00
break
fi
2019-04-04 04:57:57 +01:00
# wait 2 seconds for key input
read -n 1 -t 2 keyPressed
2018-08-09 15:06:06 +02:00
2019-04-04 04:57:57 +01:00
# check if user wants to abort session
if [ "${keyPressed}" = "x" ]; then
2019-04-04 05:03:03 +01:00
echo
echo $result
echo
echo "Returning to menu - invoice was not payed yet."
2019-04-04 04:57:57 +01:00
break
fi
done
2020-01-25 00:04:02 +01:00
/home/admin/config.scripts/blitz.lcd.sh hide
2019-04-04 04:57:57 +01:00
2019-04-04 05:16:54 +01:00
fi