Browse Source

pay invoice added

#146
rootzoll 6 years ago
parent
commit
f5d2b4c823
  1. 14
      home.admin/00mainMenu.sh
  2. 1
      home.admin/80scanLND.sh
  3. 103
      home.admin/BBpayInvoice.sh

14
home.admin/00mainMenu.sh

@ -71,6 +71,8 @@ else
FUNDING "Fund your Wallet" \
CONNECT "Connect to a Peer" \
CHANNEL "Open a Channel with Peer" \
SEND "Pay an Invoice/PaymentRequest" \
RECEIVE "Create Invoice/PaymentRequest" \
lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
@ -153,6 +155,18 @@ case $CHOICE in
read key
./00mainMenu.sh
;;
SEND)
./BBpayInvoice.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
RECEIVE)
echo "TODO: Implement BBcreateInvoice.sh"
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
CLOSEALL)
./BBcloseAllChannels.sh
echo "Press ENTER to return to main menu."

1
home.admin/80scanLND.sh

@ -31,4 +31,5 @@ if [ ${isWaitingBlockchain} -gt 0 ]; then
fi
# display progress to user
sleep 1
dialog --backtitle "RaspiBlitz (${localip} / ${network} / ${chain})" --infobox "${infoStr}" 4 42

103
home.admin/BBpayInvoice.sh

@ -0,0 +1,103 @@
#!/bin/bash
_temp="./download/dialog.$$"
_error="./.error.out"
# load network and chain info
network=`cat .network`
chain=$(sudo -bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain')
echo ""
echo "*** Precheck ***"
# check if chain is in sync
chainInSync=$(lncli getinfo | grep '"synced_to_chain": true' -c)
if [ ${chainInSync} -eq 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!"
echo "FAIL - 'lncli getinfo' shows 'synced_to_chain': false"
echo "Wait until chain is sync with LND and try again."
echo "!!!!!!!!!!!!!!!!!!!"
echo ""
exit 1
fi
# check number of connected peers
echo "check for open channels"
openChannels=$(sudo -u bitcoin lncli listchannels 2>/dev/null | grep chan_id -c)
if [ ${openChannels} -eq 0 ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!"
echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first."
echo "!!!!!!!!!!!!!!!!!!!"
echo ""
exit 1
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 $_temp
if [ ${#invoice} -eq 0 ]; then
echo "FAIL - not a valid input (${invoice})"
exit 1
fi
# build command
command="lncli sendpayment --pay_req=${invoice}"
# info output
clear
echo "******************************"
echo "Pay Invoice / Payment Request"
echo "******************************"
echo ""
echo "COMMAND LINE: "
echo $command
echo ""
echo "RESULT:"
# 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
echo "******************************"
echo "WIN"
echo "******************************"
echo "${result}"
fi
echo ""
Loading…
Cancel
Save