From 3b7d7748fa0ca5c42ccaa14c33d7d62f98a87141 Mon Sep 17 00:00:00 2001 From: rootzoll Date: Mon, 3 Dec 2018 16:16:12 +0100 Subject: [PATCH] updated to new config and added more edge case info --- home.admin/BBcashoutWallet.sh | 38 +++++++++++++++++++++++++------- home.admin/BBcloseAllChannels.sh | 21 +++++++++--------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/home.admin/BBcashoutWallet.sh b/home.admin/BBcashoutWallet.sh index 912e36e61..0b09aeabb 100755 --- a/home.admin/BBcashoutWallet.sh +++ b/home.admin/BBcashoutWallet.sh @@ -2,17 +2,39 @@ _temp="./download/dialog.$$" _error="./.error.out" -# load network and chain info -network=`cat .network` -chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') +# load raspiblitz config data (with backup from old config) +source /mnt/hdd/raspiblitz.conf 2>/dev/null +if [ ${#network} -eq 0 ]; then network=`cat .network`; fi +if [ ${#chain} -eq 0 ]; then + chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') +fi + +# check if user has money in lightning channels - info about close all +openChannels=$(lncli --chain=${network} listchannels 2>/dev/null | jq '.[] | length') +if [ ${#openChannels} -eq 0 ]; then + echo "*** IMPORTANT **********************************" + echo "It looks like LND is not responding." + echo "Still starting up, is locked or is not running?" + echo "Try later, try reboot or check ./XXdebugLogs.sh" + echo "************************************************" + exit 1 +fi +if [ ${openChannels} -gt 0 ]; then + dialog --title 'Info' --msgbox 'You still have funds in open Lightning Channels.\nUse CLOSEALL first if you want to cashout all funds.\nNOTICE: Just confirmed on-chain funds can be moved.' 7 58 +fi + +# check if money is waiting to get confirmed +unconfirmed=$(lncli --chain=${network} walletbalance | grep '"unconfirmed_balance"' | cut -d '"' -f4) +if [ ${unconfirmed} -gt 0 ]; then + dialog --title 'Info' --msgbox "Still waiting confirmation for ${unconfirmed} sat.\nNOTICE: Just confirmed on-chain funds can be moved." 6 58 +fi # get available amount in on-chain wallet maxAmount=$(lncli --chain=${network} walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) - -# TODO: pre-check if channels are open or are still in closing -# and let user know not all funds are available yet (just info Dialoge) - -# TODO: pre-check user hast more than 0 sat in on-chain wallet to send +if [ ${maxAmount} -gt 0 ]; then + dialog --title 'Info' --msgbox "You have 0 moveable funds available.\nNOTICE: Just confirmed on-chain funds can be moved." 6 58 + exit 1 +fi # let user enter the amount l1="Enter the amount of funds you want to send/remove:" diff --git a/home.admin/BBcloseAllChannels.sh b/home.admin/BBcloseAllChannels.sh index c99341fd8..005f9c8a7 100755 --- a/home.admin/BBcloseAllChannels.sh +++ b/home.admin/BBcloseAllChannels.sh @@ -1,18 +1,17 @@ #!/bin/bash -source /mnt/hdd/raspiblitz.conf -if [ "${autoPilot}" = "on" ]; then - echo "*** IMPORTANT **********************************" - echo "You need to turn OFF the LND AutoPilot first," - echo "so that closed channels are not opening up again." - echo "You find the AutoPilot -----> SERVICES section" - echo "************************************************" - exit 1 +# load raspiblitz config data (with backup from old config) +source /mnt/hdd/raspiblitz.conf 2>/dev/null +if [ ${#network} -eq 0 ]; then network=`cat .network`; fi +if [ ${#chain} -eq 0 ]; then + chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') fi -# load network and chain info -network=`cat .network` -chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') +# precheck: AutoPilot +if [ "${autoPilot}" = "on" ]; then + dialog --title 'Info' --msgbox 'You need to turn OFF the LND AutoPilot first,\nso that closed channels are not opening up again.\nYou find the AutoPilot -----> SERVICES section' 7 55 + exit 1 +fi command="lncli --chain=${network} closeallchannels --force"