mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-21 14:11:06 +02:00
cln: add CHANNEL
This commit is contained in:
@@ -25,7 +25,7 @@ OPTIONS=()
|
|||||||
|
|
||||||
OPTIONS+=(FUNDING "Fund your C-Lightning Wallet")
|
OPTIONS+=(FUNDING "Fund your C-Lightning Wallet")
|
||||||
OPTIONS+=(PEERING "Connect to a Peer")
|
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+=(SEND "Pay an Invoice/PaymentRequest")
|
||||||
#TODO OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest")
|
#TODO OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest")
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ case $CHOICE in
|
|||||||
/home/admin/BBcashoutWallet.sh
|
/home/admin/BBcashoutWallet.sh
|
||||||
;;
|
;;
|
||||||
CHANNEL)
|
CHANNEL)
|
||||||
/home/admin/BBopenChannel.sh
|
/home/admin/BBopenChannel.sh cln $NETWORK
|
||||||
;;
|
;;
|
||||||
SEND)
|
SEND)
|
||||||
/home/admin/BBpayInvoice.sh
|
/home/admin/BBpayInvoice.sh
|
||||||
|
@@ -63,9 +63,9 @@ fi
|
|||||||
l1="Enter the node pubkey address with host information:"
|
l1="Enter the node pubkey address with host information:"
|
||||||
l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735"
|
l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735"
|
||||||
if [ "$chain" = "main" ]; then
|
if [ "$chain" = "main" ]; then
|
||||||
l3="node directory -> 1ml.com"
|
l3="node directory -> https://1ml.com"
|
||||||
elif [ "$chain" = "test" ]; then
|
elif [ "$chain" = "test" ]; then
|
||||||
l3="node directory -> 1ml.com/testnet"
|
l3="node directory -> https://1ml.com/testnet"
|
||||||
fi
|
fi
|
||||||
dialog --title "Open a Connection to a Peer" \
|
dialog --title "Open a Connection to a Peer" \
|
||||||
--backtitle "Lightning ( ${network} | ${chain} )" \
|
--backtitle "Lightning ( ${network} | ${chain} )" \
|
||||||
|
@@ -12,38 +12,102 @@ if [ ${#chain} -eq 0 ]; then
|
|||||||
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
chain=$(${network}-cli getblockchaininfo | jq -r '.chain')
|
||||||
fi
|
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 ""
|
||||||
echo "*** Precheck ***"
|
echo "*** Precheck ***"
|
||||||
|
|
||||||
# check if chain is in sync
|
# PRECHECK) check if chain is in sync
|
||||||
chainInSync=$(lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": true' -c)
|
if [ $LNTYPE = cln ];then
|
||||||
if [ ${chainInSync} -eq 0 ]; then
|
BLOCKHEIGHT=$(bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
|
||||||
echo "FAIL - 'lncli getinfo' shows 'synced_to_chain': false"
|
CLHEIGHT=$(lightningcli_alias getinfo | jq .blockheight)
|
||||||
echo "Wait until chain is sync with LND and try again."
|
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
|
||||||
echo ""
|
chainOutSync=0
|
||||||
echo "Press ENTER to return to main menu."
|
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
|
read key
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
echo "# OK - the chain is synced"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check available funding
|
# 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
|
if [ ${confirmedBalance} -eq 0 ]; then
|
||||||
echo "FAIL - You have 0 SATOSHI in your confirmed LND On-Chain Wallet."
|
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 "Please fund your on-chain wallet first and wait until confirmed."
|
||||||
echo ""
|
echo
|
||||||
echo "Press ENTER to return to main menu."
|
echo "Press ENTER to return to main menu."
|
||||||
read key
|
read key
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check number of connected peers
|
# 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
|
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 "You can only open channels to peer nodes to connected to first."
|
||||||
echo "Use CONNECT peer option in main menu first."
|
echo "Use CONNECT peer option in main menu first."
|
||||||
echo ""
|
echo
|
||||||
echo "Press ENTER to return to main menu."
|
echo "Press ENTER to return to main menu."
|
||||||
read key
|
read key
|
||||||
exit 1
|
exit 1
|
||||||
@@ -51,12 +115,21 @@ fi
|
|||||||
|
|
||||||
# let user pick a peer to open a channels with
|
# let user pick a peer to open a channels with
|
||||||
OPTIONS=()
|
OPTIONS=()
|
||||||
while IFS= read -r grepLine
|
if [ $LNTYPE = cln ];then
|
||||||
do
|
while IFS= read -r grepLine
|
||||||
pubKey=$(echo ${grepLine} | cut -d '"' -f4)
|
do
|
||||||
#echo "grepLine(${pubKey})"
|
pubKey=$(echo ${grepLine} | cut -d '"' -f4)
|
||||||
OPTIONS+=(${pubKey} "")
|
# echo "grepLine(${pubKey})"
|
||||||
done < <(lncli --chain=${network} --network=${chain}net listpeers | grep pub_key)
|
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"
|
TITLE="Open (Payment) Channel"
|
||||||
MENU="\nChoose a peer you connected to, to open the channel with: \n "
|
MENU="\nChoose a peer you connected to, to open the channel with: \n "
|
||||||
pubKey=$(dialog --clear \
|
pubKey=$(dialog --clear \
|
||||||
@@ -68,11 +141,11 @@ pubKey=$(dialog --clear \
|
|||||||
|
|
||||||
clear
|
clear
|
||||||
if [ ${#pubKey} -eq 0 ]; then
|
if [ ${#pubKey} -eq 0 ]; then
|
||||||
clear
|
clear
|
||||||
echo
|
echo
|
||||||
echo "no channel selected - returning to menu ..."
|
echo "no channel selected - returning to menu ..."
|
||||||
sleep 4
|
sleep 4
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# find out what is the minimum amount
|
# find out what is the minimum amount
|
||||||
@@ -82,15 +155,17 @@ minSat=20000
|
|||||||
if [ "${network}" = "bitcoin" ]; then
|
if [ "${network}" = "bitcoin" ]; then
|
||||||
minSat=50000
|
minSat=50000
|
||||||
fi
|
fi
|
||||||
_error="./.error.out"
|
if [ $LNTYPE = lnd ];then
|
||||||
lncli --chain=${network} openchannel --network=${chain}net ${CHOICE} 1 0 2>$_error
|
_error="./.error.out"
|
||||||
error=`cat ${_error}`
|
lncli_alias openchannel ${pubkey} 1 0 2>$_error
|
||||||
if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then
|
error=$(cat ${_error})
|
||||||
minSat=$(echo "${error}" | tr -dc '0-9')
|
if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then
|
||||||
|
minSat=$(echo "${error}" | tr -dc '0-9')
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# let user enter an amount
|
# 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}"
|
l2="min required : ${minSat}"
|
||||||
l3="max available : ${confirmedBalance}"
|
l3="max available : ${confirmedBalance}"
|
||||||
dialog --title "Funding of Channel" \
|
dialog --title "Funding of Channel" \
|
||||||
@@ -119,22 +194,27 @@ if [ ${#conf_target} -eq 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# build command
|
# 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
|
# info output
|
||||||
clear
|
clear
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo "Open Channel"
|
echo "Open Channel"
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo ""
|
echo
|
||||||
echo "COMMAND LINE: "
|
echo "COMMAND LINE: "
|
||||||
echo $command
|
echo $command
|
||||||
echo ""
|
echo
|
||||||
echo "RESULT:"
|
echo "RESULT:"
|
||||||
|
|
||||||
# execute command
|
# execute command
|
||||||
result=$($command 2>$_error)
|
result=$(eval $command 2>$_error)
|
||||||
error=`cat ${_error}`
|
error=$(cat ${_error})
|
||||||
|
|
||||||
#echo "result(${result})"
|
#echo "result(${result})"
|
||||||
#echo "error(${error})"
|
#echo "error(${error})"
|
||||||
@@ -149,20 +229,33 @@ else
|
|||||||
echo "WIN"
|
echo "WIN"
|
||||||
echo "******************************"
|
echo "******************************"
|
||||||
echo "${result}"
|
echo "${result}"
|
||||||
echo ""
|
echo
|
||||||
echo "Whats next? --> You need to wait 3 confirmations, for the channel to be ready."
|
echo "What's next? --> You need to wait 3 confirmations for the channel to be ready."
|
||||||
fundingTX=$(echo "${result}" | grep 'funding_txid' | cut -d '"' -f4)
|
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 [ "${network}" = "bitcoin" ]; then
|
||||||
if [ "${chain}" = "main" ]; then
|
if [ "${chain}" = "main" ]; then
|
||||||
echo "https://live.blockcypher.com/btc/tx/${fundingTX}"
|
#echo "https://live.blockcypher.com/btc/tx/${fundingTX}"
|
||||||
else
|
echo "https://mempool.space/tx/${fundingTX}"
|
||||||
echo "https://live.blockcypher.com/btc-testnet/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
|
||||||
fi
|
fi
|
||||||
if [ "${network}" = "litecoin" ]; then
|
if [ "${network}" = "litecoin" ]; then
|
||||||
echo "https://live.blockcypher.com/ltc/tx/${fundingTX}/"
|
echo "https://live.blockcypher.com/ltc/tx/${fundingTX}/"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo
|
||||||
echo "Press ENTER to return to main menu."
|
echo "Press ENTER to return to main menu."
|
||||||
read key
|
read key
|
Reference in New Issue
Block a user