Skip to content

Commit

Permalink
devtools: Add fund_ln command to startup_regtest.sh
Browse files Browse the repository at this point in the history
fund_ln connects the two peers and funds a channel between them.

Changelog-Added: Added fund_ln to the contrib/startup_regtest.sh
  • Loading branch information
ddustin committed May 18, 2022
1 parent f90ee0e commit 2ea01af
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion contrib/startup_regtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ start_ln() {
# Kick it out of initialblockdownload if necessary
if bitcoin-cli -regtest getblockchaininfo | grep -q 'initialblockdownload.*true'; then
# Modern bitcoind needs createwallet
echo "Making \"default\" bitcoind wallet."
bitcoin-cli -regtest createwallet default >/dev/null 2>&1
bitcoin-cli -regtest generatetoaddress 1 "$(bitcoin-cli -regtest getnewaddress)" > /dev/null
else
bitcoin-cli -regtest loadwallet default
fi
alias bt-cli='bitcoin-cli -regtest'

Expand All @@ -145,7 +148,78 @@ start_ln() {
nodes="$1"
fi
start_nodes "$nodes" regtest
echo " bt-cli, stop_ln"
echo " bt-cli, stop_ln, fund_ln"
}

fund_ln() {

if [ -z "$1" ]; then
node1=1
else
node1="$1"
fi

if [ -z "$2" ]; then
node2=2
else
node2="$2"
fi

if [ -z "$3" ]; then
WALLET="-rpcwallet=default"
else
WALLET="-rpcwallet=$3"
fi

ADDRESS=$(bitcoin-cli "$WALLET" -regtest getnewaddress)

echo "minning into address " "$ADDRESS"

bitcoin-cli -regtest generatetoaddress 100 "$ADDRESS" > /dev/null

echo "Mined into $ADDRESS, checking balance"
bitcoin-cli -regtest "$WALLET" getbalance

L2_NODE_ID=$($LCLI --lightning-dir=/tmp/l"$node2"-regtest getinfo | jq -r .id)
L2_NODE_PORT=$($LCLI --lightning-dir=/tmp/l"$node2"-regtest getinfo | jq .binding[0].port)

echo "Connecting to Node 2 id/port : $L2_NODE_ID:$L2_NODE_PORT"

$LCLI --lightning-dir=/tmp/l"$node1"-regtest connect "$L2_NODE_ID"@localhost:"$L2_NODE_PORT"

L1_WALLET_ADDR=$($LCLI --lightning-dir=/tmp/l"$node1"-regtest newaddr | jq -r .bech32)

bitcoin-cli -regtest "$WALLET" sendtoaddress "$L1_WALLET_ADDR" 49

bitcoin-cli -regtest generatetoaddress 1 "$ADDRESS" > /dev/null

echo "Waiting for ln funds..."

while ! $LCLI -F --lightning-dir=/tmp/l"$node1"-regtest listfunds | grep "outputs" > /dev/null
do
sleep 1
done

echo "Funding channel"

CHANNEL_RESULT=$($LCLI --lightning-dir=/tmp/l"$node1"-regtest fundchannel "$L2_NODE_ID" 1000000)

echo fundchannel result: "$CHANNEL_RESULT"

L_CHANNEL_ID=$(echo "$CHANNEL_RESULT" | jq -r .channel_id)

echo channel id is: "$L_CHANNEL_ID"

bitcoin-cli -regtest generatetoaddress 6 "$ADDRESS" > /dev/null

echo "Waiting for channel confirmation..."

while ! $LCLI -F --lightning-dir=/tmp/l"$node1"-regtest listchannels | grep "channels" > /dev/null
do
sleep 1
done

$LCLI --lightning-dir=/tmp/l"$node1"-regtest listchannels
}

stop_nodes() {
Expand Down

0 comments on commit 2ea01af

Please sign in to comment.