2018-08-02 03:50:31 +02:00
#!/bin/bash
2019-04-04 02:07:01 +01:00
clear
2018-08-02 03:50:31 +02:00
2018-12-05 15:27:44 +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 15:27:44 +01:00
if [ ${# network } -eq 0 ] ; then network = ` cat .network` ; fi
2019-01-25 21:56:24 +01:00
if [ ${# network } -eq 0 ] ; then network = "bitcoin" ; fi
2018-12-05 15:27:44 +01:00
if [ ${# chain } -eq 0 ] ; then
echo "gathering chain info ... please wait"
chain = $( ${ network } -cli getblockchaininfo | jq -r '.chain' )
fi
2018-08-02 03:50:31 +02:00
2021-05-22 15:52:12 +01:00
# 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 "
2018-08-08 17:36:04 +02:00
# PRECHECK) check if chain is in sync
2021-05-22 15:52:12 +01:00
if [ $LNTYPE = cln ] ; then
BLOCKHEIGHT = $( bitcoincli_alias getblockchaininfo| grep blocks| awk '{print $2}' | cut -d, -f1)
CLHEIGHT = $( lightningcli_alias getinfo | jq .blockheight)
if [ $BLOCKHEIGHT -eq $CLHEIGHT ] ; then
chainOutSync = 0
else
chainOutSync = 1
fi
else
chainOutSync = $( lncli_alias getinfo | grep '"synced_to_chain": false' -c)
fi
2019-03-08 13:16:43 +00:00
if [ ${ chainOutSync } -eq 1 ] ; then
2021-05-22 15:52:12 +01:00
if [ $LNTYPE = cln ] ; then
echo "# FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync "
else
echo "# FAIL PRECHECK - 'lightning-cli getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync "
fi
echo
echo "# PRESS ENTER to return to menu"
2019-04-04 02:29:04 +01:00
read key
2019-04-04 02:07:01 +01:00
exit 1
2021-05-22 15:52:12 +01:00
else
echo "# OK - the chain is synced"
2018-08-08 17:36:04 +02:00
fi
2018-08-02 03:50:31 +02:00
# execute command
2021-05-22 15:52:12 +01:00
if [ $LNTYPE = cln ] ; then
command = " $lightningcli_alias newaddr bech32 "
else
command = " $lncli_alias newaddress p2wkh "
fi
echo "# Calling:"
2019-04-04 02:07:01 +01:00
echo " ${ command } "
2021-05-22 15:52:12 +01:00
echo
2019-04-04 02:07:01 +01:00
result = $( $command )
echo " $result "
2018-08-02 03:50:31 +02:00
# on no result
if [ ${# result } -eq 0 ] ; then
2021-05-22 15:52:12 +01:00
echo "# Empty result - sorry something went wrong - that is unusual."
echo
echo "# Press ENTER to return to menu"
2019-04-04 02:29:04 +01:00
read key
2018-08-02 03:50:31 +02:00
exit 1
fi
2019-04-04 02:07:01 +01:00
# parse address from result
2018-08-02 03:50:31 +02:00
address = $( echo " $result " | grep "address" | cut -d '"' -f4)
# prepare coin info
2019-04-04 02:07:01 +01:00
coininfo = "Bitcoin"
2018-08-02 03:50:31 +02:00
if [ " $network " = "litecoin" ] ; then
2019-04-04 02:07:01 +01:00
coininfo = "Litecoin"
2018-08-02 03:50:31 +02:00
fi
if [ " $chain " = "test" ] ; then
coininfo = "TESTNET Bitcoin"
fi
2020-02-17 13:32:33 +01:00
msg = " Send ${ coininfo } to address --> ${ address } \n\nScan the QR code on the LCD with your mobile wallet or copy paste the address.\nThe wallet you sending from needs to support bech32 addresses.\nThis screen will not update - press DONE when send. "
2018-08-02 03:50:31 +02:00
if [ " $chain " = "test" ] ; then
2019-02-24 07:08:33 +01:00
msg = " ${ msg } \n\n Get some testnet coins from https://testnet-faucet.mempool.co "
2018-08-02 03:50:31 +02:00
fi
2019-02-23 16:38:06 +01:00
2019-04-04 02:07:01 +01:00
echo "generating QR code ... please wait"
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh qr " $network : ${ address } "
2019-02-23 16:38:06 +01:00
2019-04-04 02:07:01 +01:00
# dialog with instructions while QR code is shown on LCD
2021-05-22 15:52:12 +01:00
whiptail --backtitle "Fund your onchain wallet" \
2019-02-24 07:08:33 +01:00
--title " Send ${ coininfo } " \
2019-04-04 02:07:01 +01:00
--yes-button "DONE" \
2020-04-05 10:33:17 +02:00
--no-button "Console QRcode" \
2019-04-04 02:07:01 +01:00
--yesno " ${ msg } " 0 0
2019-02-24 07:08:33 +01:00
2019-04-04 02:07:01 +01:00
# display QR code
if [ $? -eq 1 ] ; then
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh qr-console " $network : ${ address } "
2019-02-24 07:08:33 +01:00
fi
2019-04-04 02:07:01 +01:00
# clean up
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh hide
2019-02-24 07:08:33 +01:00
2019-04-04 02:07:01 +01:00
# follow up info
2021-05-22 15:52:12 +01:00
if [ $LNTYPE = cln ] ; then
string = "Wait for confirmations."
else
string = "Wait for confirmations. \n\nYou can use info on LCD to check if funds have arrived. \n\nIf you want your lighting node to open channels automatically, activate the 'Autopilot' under 'Activate/Deactivate Services'"
fi
whiptail --backtitle "Fund your onchain wallet" \
2019-02-24 07:08:33 +01:00
--title "What's next?" \
2021-05-22 15:52:12 +01:00
--msgbox " $string " 0 0