raspiblitz/home.admin/BBpayInvoice.sh

107 lines
2.8 KiB
Bash
Raw Normal View History

2018-08-09 14:44:45 +02:00
#!/bin/bash
2020-02-17 14:12:54 +01:00
clear
2018-08-09 14:44:45 +02:00
_temp="./download/dialog.$$"
_error="./.error.out"
2020-02-17 14:12:54 +01:00
sudo chmod 7777 ${_error} 2>/dev/null
2018-08-09 14:44:45 +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:44:45 +02:00
# Check if ready (chain in sync and channels open)
./XXchainInSync.sh $network $chain
if [ $? != 0 ]; then
exit 1
2018-08-09 14:44:45 +02:00
fi
paymentRequestStart="???"
if [ "${network}" = "bitcoin" ]; then
if [ "${chain}" = "main" ]; then
paymentRequestStart="lnbc"
else
paymentRequestStart="lntb"
fi
elif [ "${network}" = "litecoin" ]; then
paymentRequestStart="lnltc"
fi
testSite="???"
if [ "${network}" = "bitcoin" ]; then
if [ "${chain}" = "main" ]; then
testSite="https://satoshis.place"
else
testSite="https://testnet.satoshis.place"
fi
elif [ "${network}" = "litecoin" ]; then
testSite="https://millionlitecoinhomepage.net"
fi
# let user enter the invoice
l1="Copy the LightningInvoice/PaymentRequest into here:"
l2="Its a long string starting with '${paymentRequestStart}'"
l3="To try it out go to: ${testSite}"
dialog --title "Pay thru Lightning Network" \
--inputbox "$l1\n$l2\n$l3" 10 70 2>$_temp
invoice=$(cat $_temp | xargs)
shred -u $_temp
2018-08-09 14:44:45 +02:00
if [ ${#invoice} -eq 0 ]; then
2020-02-17 20:47:37 +01:00
clear
echo
echo "no invoice entered - returning to menu ..."
sleep 2
2018-08-09 14:44:45 +02:00
exit 1
fi
2018-08-09 14:58:44 +02:00
# TODO: maybe try/show the decoded info first by using https://api.lightning.community/#decodepayreq
2018-08-09 14:44:45 +02:00
# build command
2018-12-05 16:19:06 +01:00
command="lncli --chain=${network} --network=${chain}net sendpayment --force --pay_req=${invoice}"
2018-08-09 14:44:45 +02:00
# info output
clear
2019-02-12 20:24:44 +01:00
echo "************************************************************"
2018-08-09 14:44:45 +02:00
echo "Pay Invoice / Payment Request"
2019-02-12 20:24:44 +01:00
echo "This script is as an example how to use the lncli interface."
echo "Its not optimized for performance or error handling."
echo "************************************************************"
2018-08-09 14:44:45 +02:00
echo ""
echo "COMMAND LINE: "
echo $command
echo ""
2018-08-09 14:58:44 +02:00
echo "RESULT (may wait in case of timeout):"
2018-08-09 14:44:45 +02:00
# execute command
result=$($command 2>$_error)
error=`cat ${_error}`
#echo "result(${result})"
#echo "error(${error})"
2019-02-12 20:24:44 +01:00
resultIsError=$(echo "${result}" | grep -c "payment_error")
if [ ${resultIsError} -gt 0 ]; then
error="${result}"
fi
2018-08-09 14:44:45 +02:00
if [ ${#error} -gt 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL"
2019-02-12 20:24:44 +01:00
echo "try with a wallet app or the RTL WebGUI (see services)"
2018-08-09 14:44:45 +02:00
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "${error}"
else
2018-08-09 14:58:44 +02:00
echo "${result}"
2018-08-09 14:44:45 +02:00
echo "******************************"
echo "WIN"
echo "******************************"
2018-08-09 14:58:44 +02:00
echo "It worked :) - check out the service you were paying."
2018-08-09 14:44:45 +02:00
fi
echo ""
2020-02-17 20:50:06 +01:00
echo "Press ENTER to return to main menu."
read key