From 982a4d593fcbe177dacab5d7acbd449903cb3929 Mon Sep 17 00:00:00 2001 From: openoms Date: Mon, 5 Jul 2021 23:42:55 +0100 Subject: [PATCH] CASHOUT: use aliases for lnd --- home.admin/BBcashoutWallet.sh | 45 +++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/home.admin/BBcashoutWallet.sh b/home.admin/BBcashoutWallet.sh index 06d196ab4..90c5c15d7 100755 --- a/home.admin/BBcashoutWallet.sh +++ b/home.admin/BBcashoutWallet.sh @@ -10,15 +10,24 @@ source /mnt/hdd/raspiblitz.conf if [ ${#network} -eq 0 ]; then network=$(cat .network); fi if [ ${#network} -eq 0 ]; then network="bitcoin"; fi if [ ${#chain} -eq 0 ]; then - chain=$(${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | jq -r '.chain') + chain=$($bitcoincli_alias getblockchaininfo | jq -r '.chain') fi +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) + # check if user has money in lightning channels - info about close all -openChannels=$(lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | jq '.[] | length') +if [ $LNTYPE = cln ];then + ln_getInfo=$($lightningcli_alias getinfo 2>/dev/null) + ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null + cln_num_inactive_channels="$(echo "${ln_getInfo}" | jq -r '.num_inactive_channels')" 2>/dev/null + openChannels=$((ln_channels_online+cln_num_inactive_channels)) +elif [ $LNTYPE = lnd ];then + openChannels=$($lncli_alias listchannels 2>/dev/null | jq '.[] | length') +fi if [ ${#openChannels} -eq 0 ]; then clear echo "*** IMPORTANT **********************************" - echo "It looks like LND is not responding." + echo "It looks like $LNTYPE is not responding." echo "Still starting up, is locked or is not running?" echo "Try later, try reboot or run command: debug" echo "************************************************" @@ -36,7 +45,17 @@ if [ ${openChannels} -gt 0 ]; then fi # check if money is waiting to get confirmed -unconfirmed=$(lncli --chain=${network} --network=${chain}net walletbalance | grep '"unconfirmed_balance"' | cut -d '"' -f4) +if [ $LNTYPE = cln ];then + ln_walletbalance_wait=0 + cln_listfunds=$($lightningcli_alias listfunds 2>/dev/null) + for i in $(echo "$cln_listfunds" \ + |jq .outputs[]|jq 'select(.status=="unconfirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do + ln_walletbalance_wait=$((ln_walletbalance_wait+i)) + done + unconfirmed=$ln_walletbalance_wait +elif [ $LNTYPE = lnd ];then + unconfirmed=$($lncli_alias walletbalance | grep '"unconfirmed_balance"' | cut -d '"' -f4) +fi if [ ${unconfirmed} -gt 0 ]; then whiptail --title 'Info' --yes-button='Cashout Anyway' --no-button='Go Back' --yesno "Still waiting confirmation for (some of) your funds.\nNOTICE: Just confirmed on-chain funds can be moved." 8 58 if [ $? -eq 1 ]; then @@ -70,22 +89,28 @@ echo "Sweep all possible Funds" echo "******************************" # execute command -command="lncli --chain=${network} --network=${chain}net sendcoins --sweepall --addr=${address} --conf_target=36" +if [ ${LNTYPE} = "cln" ];then + # TODO no easy way to sweep funds + # withdraw destination satoshi [feerate] [minconf] [utxos] + command="NOT IMPLEMENTED YET" +elif [ ${LNTYPE} = "lnd" ];then + command="$lncli_alias sendcoins --sweepall --addr=${address} --conf_target=36" +fi echo "$command" result=$($command 2>$_error) -error=`cat ${_error}` -echo "" +error=$(cat ${_error}) +echo if [ ${#error} -gt 0 ]; then echo "FAIL: $error" - echo "" + echo echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "FAIL --> Was not able to send transaction (see error above)" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" else echo "Result: $result" - echo "" + echo echo "********************************************************************" fi -echo "" +echo echo "Press ENTER to return to main menu." read key \ No newline at end of file