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
2021-08-04 00:18:30 +02: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-08-04 00:18:30 +02:00
source <( /home/admin/config.scripts/network.aliases.sh getvars $1 $2 )
2018-08-08 17:36:04 +02:00
# PRECHECK) check if chain is in sync
2021-09-26 10:30:09 +01:00
if [ $LNTYPE = cl ] ; then
2021-08-04 00:18:30 +02:00
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
elif [ $LNTYPE = lnd ] ; then
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-09-26 10:30:09 +01:00
if [ $LNTYPE = cl ] ; then
2022-01-25 12:07:11 +01:00
echo " # FAIL PRECHECK - ' $lightningcli_alias getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync "
2021-08-04 00:18:30 +02:00
else
2022-01-25 12:07:11 +01:00
echo " # FAIL PRECHECK - ' $lncli_alias getinfo' shows 'synced_to_chain': false - wait until chain is sync "
2021-08-04 00:18:30 +02:00
fi
echo
echo "# PRESS ENTER to return to menu"
2019-04-04 02:29:04 +01:00
read key
2021-08-04 00:18:30 +02:00
exit 0
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-09-26 10:30:09 +01:00
if [ $LNTYPE = cl ] ; then
2021-08-04 00:18:30 +02:00
command = " $lightningcli_alias newaddr bech32 "
elif [ $LNTYPE = lnd ] ; then
command = " $lncli_alias newaddress p2wkh "
fi
echo "# Calling:"
2019-04-04 02:07:01 +01:00
echo " ${ command } "
2021-08-04 00:18:30 +02: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-08-04 00:18:30 +02: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
2021-08-04 00:18:30 +02:00
2019-04-04 02:07:01 +01:00
# parse address from result
2021-09-26 10:30:09 +01:00
if [ $LNTYPE = cl ] ; then
2021-08-04 00:18:30 +02:00
address = $( echo " $result " | grep "bech32" | cut -d '"' -f4)
elif [ $LNTYPE = lnd ] ; then
address = $( echo " $result " | grep "address" | cut -d '"' -f4)
fi
2018-08-02 03:50:31 +02:00
# prepare coin info
2019-04-04 02:07:01 +01:00
coininfo = "Bitcoin"
2018-08-02 03:50:31 +02:00
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"
2022-02-13 12:23:34 +00:00
sudo /home/admin/config.scripts/blitz.display.sh qr " $network : ${ address } "
2019-02-23 16:38:06 +01:00
2021-12-14 23:34:35 +01:00
# raise high focus on onchain wallet balance & pending for the next 15min
2021-12-20 19:24:36 +00:00
/home/admin/_cache.sh focus ln_${ LNTYPE } _${ chain } net_wallet_onchain_pending 0 900
/home/admin/_cache.sh focus ln_${ LNTYPE } _${ chain } net_wallet_onchain_balance 0 900
2021-12-14 23:34:35 +01:00
2019-04-04 02:07:01 +01:00
# dialog with instructions while QR code is shown on LCD
2021-08-04 00:18:30 +02: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
2022-02-13 12:23:34 +00:00
sudo /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-09-26 10:30:09 +01:00
if [ $LNTYPE = cl ] ; then
2021-08-04 00:18:30 +02:00
string = "Wait for confirmations."
elif [ $LNTYPE = lnd ] ; then
2021-09-26 10:30:09 +01:00
string = "Wait for confirmations. \n\nYou can use info on LCD to check if funds have arrived. \n\nIf you want your lightning node to open channels automatically, activate the 'Autopilot' under 'Activate/Deactivate Services'"
2021-08-04 00:18:30 +02:00
fi
whiptail --backtitle "Fund your onchain wallet" \
2019-02-24 07:08:33 +01:00
--title "What's next?" \
2021-08-04 00:18:30 +02:00
--msgbox " $string " 0 0