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.
  • Loading branch information
ddustin committed Mar 1, 2022
1 parent 1da9b30 commit 31881f0
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 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."

This comment has been minimized.

Copy link
@niftynei

niftynei Mar 1, 2022

👍

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,44 @@ start_ln() {
nodes="$1"
fi
start_nodes "$nodes" regtest
echo " bt-cli, stop_ln"
echo " bt-cli, stop_ln, fund_ln"
}

fund_ln() {

This comment has been minimized.

Copy link
@niftynei

niftynei Mar 1, 2022

dope.

optionally, you could have a user pass in the numbers of the nodes to fund a channel btw

start_ln takes an optional integer argument that then creates that number of nodes.

so if i did

start_ln 3

it'll make 3 nodes, l1, l2 and l3.

then you could do fund_ln 2 3 and have it create a channel btw nodes l2 and l3, for ex.

This comment has been minimized.

Copy link
@ddustin

ddustin Mar 2, 2022

Author Owner

Added these in ElementsProject#5062


ADDRESS=`bitcoin-cli -regtest getnewaddress`
bitcoin-cli -regtest generatetoaddress 50 $ADDRESS

echo $ADDRESS
bitcoin-cli -regtest getbalance

L2_NODE_ID=`$LCLI --lightning-dir=/tmp/l2-regtest getinfo | jq -r .id`
L2_NODE_PORT=`$LCLI --lightning-dir=/tmp/l2-regtest getinfo | jq .binding[0].port`

echo "Node 2 id/port is : $L2_NODE_ID:$L2_NODE_PORT"

$LCLI --lightning-dir=/tmp/l1-regtest connect $L2_NODE_ID@localhost:$L2_NODE_PORT

$LCLI --lightning-dir=/tmp/l1-regtest listpeers

L1_WALLET_ADDR=`$LCLI --lightning-dir=/tmp/l1-regtest newaddr | jq -r .bech32`

echo bitcoin-cli -regtest sendtoaddress $L1_WALLET_ADDR 1000

bitcoin-cli -regtest sendtoaddress $L1_WALLET_ADDR 1000

bitcoin-cli -regtest generatetoaddress 6 $ADDRESS

$LCLI --lightning-dir=/tmp/l1-regtest listfunds

L_CHANNEL_ID=`$LCLI --lightning-dir=/tmp/l1-regtest fundchannel $L2_NODE_ID 1000000 | jq -r .channel_id`

echo channel id is: $L_CHANNEL_ID

bitcoin-cli -regtest generatetoaddress 12 $ADDRESS

$LCLI --lightning-dir=/tmp/l1-regtest listchannels
$LCLI --lightning-dir=/tmp/l2-regtest listchannels
}

stop_nodes() {
Expand Down

0 comments on commit 31881f0

Please sign in to comment.