diff --git a/home.admin/99clnMenu.sh b/home.admin/99clnMenu.sh index 0b3fd2ced..9853ebac9 100644 --- a/home.admin/99clnMenu.sh +++ b/home.admin/99clnMenu.sh @@ -25,7 +25,7 @@ OPTIONS=() OPTIONS+=(FUNDING "Fund your C-Lightning Wallet") OPTIONS+=(PEERING "Connect to a Peer") -#TODO OPTIONS+=(CHANNEL "Open a Channel with Peer") +OPTIONS+=(CHANNEL "Open a Channel with Peer") #TODO OPTIONS+=(SEND "Pay an Invoice/PaymentRequest") #TODO OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest") @@ -95,7 +95,7 @@ case $CHOICE in /home/admin/BBcashoutWallet.sh ;; CHANNEL) - /home/admin/BBopenChannel.sh + /home/admin/BBopenChannel.sh cln $NETWORK ;; SEND) /home/admin/BBpayInvoice.sh diff --git a/home.admin/BBconnectPeer.sh b/home.admin/BBconnectPeer.sh index 876bc9d71..bc4cd1058 100755 --- a/home.admin/BBconnectPeer.sh +++ b/home.admin/BBconnectPeer.sh @@ -63,9 +63,9 @@ fi l1="Enter the node pubkey address with host information:" l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735" if [ "$chain" = "main" ]; then - l3="node directory -> 1ml.com" + l3="node directory -> https://1ml.com" elif [ "$chain" = "test" ]; then - l3="node directory -> 1ml.com/testnet" + l3="node directory -> https://1ml.com/testnet" fi dialog --title "Open a Connection to a Peer" \ --backtitle "Lightning ( ${network} | ${chain} )" \ diff --git a/home.admin/BBopenChannel.sh b/home.admin/BBopenChannel.sh index 43ef1e100..e1ea012be 100755 --- a/home.admin/BBopenChannel.sh +++ b/home.admin/BBopenChannel.sh @@ -12,38 +12,102 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi +# 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" + echo "" echo "*** Precheck ***" -# check if chain is in sync -chainInSync=$(lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": true' -c) -if [ ${chainInSync} -eq 0 ]; then - echo "FAIL - 'lncli getinfo' shows 'synced_to_chain': false" - echo "Wait until chain is sync with LND and try again." - echo "" - echo "Press ENTER to return to main menu." +# PRECHECK) check if chain is in sync +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 +elif [ $LNTYPE = lnd ];then + chainOutSync=$(lncli_alias getinfo | grep '"synced_to_chain": false' -c) +fi +if [ ${chainOutSync} -eq 1 ]; then + 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" read key exit 1 +else + echo "# OK - the chain is synced" fi # check available funding -confirmedBalance=$(lncli --chain=${network} --network=${chain}net walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) +if [ $LNTYPE = cln ];then + for i in $(lightningcli_alias listfunds | jq .outputs | grep value | awk '{print $2}' | cut -d, -f1);do + confirmedBalance=$((confirmedBalance+i)) + done +elif [ $LNTYPE = lnd ];then + confirmedBalance=$(lncli_alias walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) +fi + if [ ${confirmedBalance} -eq 0 ]; then echo "FAIL - You have 0 SATOSHI in your confirmed LND On-Chain Wallet." echo "Please fund your on-chain wallet first and wait until confirmed." - echo "" + echo echo "Press ENTER to return to main menu." read key exit 1 fi # check number of connected peers -numConnectedPeers=$(lncli --chain=${network} --network=${chain}net listpeers | grep pub_key -c) +if [ $LNTYPE = cln ];then + numConnectedPeers=$(lightningcli_alias listpeers | grep -c '"id":') +elif [ $LNTYPE = lnd ];then + numConnectedPeers=$(lncli_alias listpeers | grep pub_key -c) +fi + if [ ${numConnectedPeers} -eq 0 ]; then - echo "FAIL - no peers connected on lightning network" + echo "FAIL - no peers connected on the lightning network" echo "You can only open channels to peer nodes to connected to first." echo "Use CONNECT peer option in main menu first." - echo "" + echo echo "Press ENTER to return to main menu." read key exit 1 @@ -51,12 +115,21 @@ fi # let user pick a peer to open a channels with OPTIONS=() -while IFS= read -r grepLine -do - pubKey=$(echo ${grepLine} | cut -d '"' -f4) - #echo "grepLine(${pubKey})" - OPTIONS+=(${pubKey} "") -done < <(lncli --chain=${network} --network=${chain}net listpeers | grep pub_key) +if [ $LNTYPE = cln ];then + while IFS= read -r grepLine + do + pubKey=$(echo ${grepLine} | cut -d '"' -f4) + # echo "grepLine(${pubKey})" + OPTIONS+=(${pubKey} "") + done < <(lightningcli_alias listpeers | grep '"id":') +elif [ $LNTYPE = lnd ];then + while IFS= read -r grepLine + do + pubKey=$(echo ${grepLine} | cut -d '"' -f4) + # echo "grepLine(${pubKey})" + OPTIONS+=(${pubKey} "") + done < <(lncli_alias listpeers | grep pub_key) +fi TITLE="Open (Payment) Channel" MENU="\nChoose a peer you connected to, to open the channel with: \n " pubKey=$(dialog --clear \ @@ -68,11 +141,11 @@ pubKey=$(dialog --clear \ clear if [ ${#pubKey} -eq 0 ]; then - clear - echo - echo "no channel selected - returning to menu ..." - sleep 4 - exit 1 + clear + echo + echo "no channel selected - returning to menu ..." + sleep 4 + exit 1 fi # find out what is the minimum amount @@ -82,15 +155,17 @@ minSat=20000 if [ "${network}" = "bitcoin" ]; then minSat=50000 fi -_error="./.error.out" -lncli --chain=${network} openchannel --network=${chain}net ${CHOICE} 1 0 2>$_error -error=`cat ${_error}` -if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then - minSat=$(echo "${error}" | tr -dc '0-9') +if [ $LNTYPE = lnd ];then + _error="./.error.out" + lncli_alias openchannel ${pubkey} 1 0 2>$_error + error=$(cat ${_error}) + if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then + minSat=$(echo "${error}" | tr -dc '0-9') + fi fi # let user enter an amount -l1="Amount in SATOSHI to fund this channel:" +l1="Amount in satoshis to fund this channel:" l2="min required : ${minSat}" l3="max available : ${confirmedBalance}" dialog --title "Funding of Channel" \ @@ -119,22 +194,27 @@ if [ ${#conf_target} -eq 0 ]; then fi # build command -command="lncli --chain=${network} --network=${chain}net openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0" - +if [ $LNTYPE = cln ];then + # fundchannel id amount [feerate] [announce] [minconf] [utxos] [push_msat] [close_to] + feerate=$(bitcoincli_alias estimatesmartfee $conf_target |grep feerate|awk '{print $2}'|cut -c 5-7|bc) + command="lightningcli_alias fundchannel ${pubKey} ${amount} $feerate" +elif [ $LNTYPE = lnd ];then + command="lncli_alias openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0" +fi # info output clear echo "******************************" echo "Open Channel" echo "******************************" -echo "" +echo echo "COMMAND LINE: " echo $command -echo "" +echo echo "RESULT:" # execute command -result=$($command 2>$_error) -error=`cat ${_error}` +result=$(eval $command 2>$_error) +error=$(cat ${_error}) #echo "result(${result})" #echo "error(${error})" @@ -149,20 +229,33 @@ else echo "WIN" echo "******************************" echo "${result}" - echo "" - echo "Whats next? --> You need to wait 3 confirmations, for the channel to be ready." - fundingTX=$(echo "${result}" | grep 'funding_txid' | cut -d '"' -f4) + echo + echo "What's next? --> You need to wait 3 confirmations for the channel to be ready." + if [ $LNTYPE = cln ];then + fundingTX=$(echo "${result}" | grep 'txid' | cut -d '"' -f4) + elif [ $LNTYPE = lnd ];then + fundingTX=$(echo "${result}" | grep 'funding_txid' | cut -d '"' -f4) + fi + echo if [ "${network}" = "bitcoin" ]; then if [ "${chain}" = "main" ]; then - echo "https://live.blockcypher.com/btc/tx/${fundingTX}" - else - echo "https://live.blockcypher.com/btc-testnet/tx/${fundingTX}" + #echo "https://live.blockcypher.com/btc/tx/${fundingTX}" + echo "https://mempool.space/tx/${fundingTX}" + elif [ "${chain}" = "test" ]||[ "${chain}" = "sig" ]; then + echo "https://mempool.space/${chain}net/tx/${fundingTX}" + fi + echo + echo "In the Tor Browser:" + if [ "${chain}" = "main" ]; then + echo "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/tx/${fundingTX}" + elif [ "${chain}" = "test" ]||[ "${chain}" = "sig" ]; then + echo "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/${chain}net/tx/${fundingTX}" fi fi if [ "${network}" = "litecoin" ]; then echo "https://live.blockcypher.com/ltc/tx/${fundingTX}/" fi fi -echo "" +echo echo "Press ENTER to return to main menu." read key \ No newline at end of file