raspiblitz/home.admin/BBfundWallet.sh

110 lines
3.4 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-04-04 02:07:01 +01:00
clear
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
if [ ${#network} -eq 0 ]; then network=$(cat .network); fi
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
source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2)
2021-05-22 15:52:12 +01:00
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)
2021-05-22 15:52:12 +01:00
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
chainOutSync=0
else
chainOutSync=1
fi
2021-05-22 18:28:14 +01:00
elif [ $LNTYPE = lnd ];then
chainOutSync=$($lncli_alias getinfo | grep '"synced_to_chain": false' -c)
2021-05-22 15:52:12 +01:00
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
2021-08-03 16:15:32 +02:00
exit 0
2021-05-22 15:52:12 +01:00
else
echo "# OK - the chain is synced"
2018-08-08 17:36:04 +02:00
fi
# execute command
2021-05-22 15:52:12 +01:00
if [ $LNTYPE = cln ];then
command="$lightningcli_alias newaddr bech32"
2021-05-22 18:28:14 +01:00
elif [ $LNTYPE = lnd ];then
2021-05-22 15:52:12 +01:00
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"
# 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
exit 1
fi
2021-06-29 19:08:39 +01:00
2019-04-04 02:07:01 +01:00
# parse address from result
2021-06-29 19:08:39 +01:00
if [ $LNTYPE = cln ];then
address=$( echo "$result" | grep "bech32" | cut -d '"' -f4)
elif [ $LNTYPE = lnd ];then
address=$( echo "$result" | grep "address" | cut -d '"' -f4)
fi
# prepare coin info
2019-04-04 02:07:01 +01:00
coininfo="Bitcoin"
if [ "$network" = "litecoin" ]; then
2019-04-04 02:07:01 +01:00
coininfo="Litecoin"
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."
if [ "$chain" = "test" ]; then
msg="${msg} \n\n Get some testnet coins from https://testnet-faucet.mempool.co"
fi
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-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" \
--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-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}"
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-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."
2021-05-22 18:28:14 +01:00
elif [ $LNTYPE = lnd ];then
2021-05-22 15:52:12 +01:00
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" \
--title "What's next?" \
2021-05-22 15:52:12 +01:00
--msgbox "$string" 0 0