mirror of
https://github.com/lightninglabs/loop
synced 2024-11-13 13:10:30 +00:00
552fdaeb28
To help with development of apps that use the Loop daemon (`loopd`) for liquidity management, it is often useful to test it in controlled environments such as on the Bitcoin `regtest` network. Lightning Labs provides a stripped down version of the Loop server that works only for `regtest` and is only published in compiled, binary form (currently as a Docker image). The `docker-compose.yml` shows an example setup and is accompanied by a quick start script that should make getting started very easy.
97 lines
2.2 KiB
Bash
Executable File
97 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# The absolute directory this file is located in.
|
|
COMPOSE="docker-compose -p regtest"
|
|
|
|
function bitcoin() {
|
|
docker exec -ti regtest_bitcoind_1 bitcoin-cli -regtest "$@"
|
|
}
|
|
|
|
function lndserver() {
|
|
docker exec -ti regtest_lndserver_1 lncli --network regtest "$@"
|
|
}
|
|
|
|
function lndclient() {
|
|
docker exec -ti regtest_lndclient_1 lncli --network regtest "$@"
|
|
}
|
|
|
|
function loop() {
|
|
docker exec -ti regtest_loopclient_1 loop --network regtest "$@"
|
|
}
|
|
|
|
function start() {
|
|
$COMPOSE up --force-recreate -d
|
|
echo "Waiting for nodes to start"
|
|
waitnodestart
|
|
setup
|
|
}
|
|
|
|
function waitnodestart() {
|
|
while ! lndserver getinfo | grep -q identity_pubkey; do
|
|
sleep 1
|
|
done
|
|
while ! lndclient getinfo | grep -q identity_pubkey; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
function mine() {
|
|
NUMBLOCKS=6
|
|
if [ ! -z "$1" ]
|
|
then
|
|
NUMBLOCKS=$1
|
|
fi
|
|
bitcoin generatetoaddress $NUMBLOCKS $(bitcoin getnewaddress "" legacy) > /dev/null
|
|
}
|
|
|
|
function setup() {
|
|
echo "Getting pubkeys"
|
|
LNDSERVER=$(lndserver getinfo | jq .identity_pubkey -r)
|
|
LNDCLIENT=$(lndclient getinfo | jq .identity_pubkey -r)
|
|
echo "Getting addresses"
|
|
|
|
echo "Creating wallet"
|
|
bitcoin createwallet miner
|
|
|
|
ADDR_BTC=$(bitcoin getnewaddress "" legacy)
|
|
echo "Generating blocks to $ADDR_BTC"
|
|
bitcoin generatetoaddress 106 "$ADDR_BTC" > /dev/null
|
|
|
|
echo "Sending funds"
|
|
ADDR_SERVER=$(lndserver newaddress p2wkh | jq .address -r)
|
|
ADDR_CLIENT=$(lndclient newaddress p2wkh | jq .address -r)
|
|
bitcoin sendtoaddress "$ADDR_SERVER" 5
|
|
bitcoin sendtoaddress "$ADDR_CLIENT" 5
|
|
mine 6
|
|
|
|
lndserver openchannel --node_key $LNDCLIENT --connect regtest_lndclient_1:9735 --local_amt 16000000
|
|
mine 6
|
|
|
|
lndclient openchannel --node_key $LNDSERVER --local_amt 16000000
|
|
mine 6
|
|
}
|
|
|
|
function stop() {
|
|
$COMPOSE down --volumes
|
|
}
|
|
|
|
function restart() {
|
|
stop
|
|
start
|
|
}
|
|
|
|
function info() {
|
|
LNDSERVER=$(lndserver getinfo | jq -c '{pubkey: .identity_pubkey, channels: .num_active_channels, peers: .num_peers}')
|
|
LNDCLIENT=$(lndclient getinfo | jq -c '{pubkey: .identity_pubkey, channels: .num_active_channels, peers: .num_peers}')
|
|
echo "lnd server: $LNDSERVER"
|
|
echo "lnd client: $LNDCLIENT"
|
|
}
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
echo "Usage: $0 start|stop|restart|info|loop"
|
|
fi
|
|
|
|
CMD=$1
|
|
shift
|
|
$CMD "$@"
|