Skip to content

Commit 8a12b40

Browse files
authored
Merge pull request #121 from synonymdev/test/setup-external-channel-helper-script
setup external channel helper script
2 parents f052a26 + 519227f commit 8a12b40

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

scripts/setup-external.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5+
COMPOSE_FILE="$ROOT/docker/docker-compose.yml"
6+
HOST="${EXTERNAL_HOST:-0.0.0.0}"
7+
PORT="${EXTERNAL_PORT:-9735}"
8+
NETWORK="${LND_NETWORK:-regtest}"
9+
LND_DIR="${LND_DIR:-/home/lnd/.lnd}"
10+
TLS_CERT_PATH="${TLS_CERT_PATH:-$LND_DIR/tls.cert}"
11+
MACAROON_PATH="${MACAROON_PATH:-$LND_DIR/data/chain/bitcoin/$NETWORK/admin.macaroon}"
12+
FUND_BTC="${FUND_BTC:-1}"
13+
14+
if ! command -v docker >/dev/null 2>&1; then
15+
echo "ERROR: docker is not installed or not in PATH" >&2
16+
exit 1
17+
fi
18+
19+
echo "Starting lnd (and required services if missing)..."
20+
docker compose -f "$COMPOSE_FILE" up -d bitcoind bitcoinsetup darkhttpd lnd >/dev/null
21+
22+
echo "Waiting for lnd to become ready..."
23+
lnd_info=""
24+
for _ in $(seq 1 90); do
25+
set +e
26+
lnd_info="$(
27+
docker compose -f "$COMPOSE_FILE" exec -T lnd \
28+
lncli \
29+
--network="$NETWORK" \
30+
--lnddir="$LND_DIR" \
31+
--tlscertpath="$TLS_CERT_PATH" \
32+
--macaroonpath="$MACAROON_PATH" \
33+
getinfo 2>/dev/null
34+
)"
35+
status=$?
36+
set -e
37+
if [[ $status -eq 0 && -n "$lnd_info" ]]; then
38+
break
39+
fi
40+
sleep 1
41+
done
42+
43+
if [[ -z "$lnd_info" ]]; then
44+
echo "ERROR: lnd did not become ready in time." >&2
45+
exit 1
46+
fi
47+
48+
LND_NODE_ID="$(python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("identity_pubkey",""))' <<<"$lnd_info")"
49+
if [[ -z "$LND_NODE_ID" ]]; then
50+
echo "ERROR: Could not read lnd identity_pubkey." >&2
51+
exit 1
52+
fi
53+
54+
echo "Funding LND wallet with ${FUND_BTC} BTC and mining 1 block..."
55+
lnd_addr_json="$(
56+
docker compose -f "$COMPOSE_FILE" exec -T lnd \
57+
lncli \
58+
--network="$NETWORK" \
59+
--lnddir="$LND_DIR" \
60+
--tlscertpath="$TLS_CERT_PATH" \
61+
--macaroonpath="$MACAROON_PATH" \
62+
newaddress p2wkh
63+
)"
64+
LND_ADDRESS="$(python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("address",""))' <<<"$lnd_addr_json")"
65+
if [[ -z "$LND_ADDRESS" ]]; then
66+
echo "ERROR: Could not get LND on-chain address." >&2
67+
exit 1
68+
fi
69+
70+
docker compose -f "$COMPOSE_FILE" exec -T bitcoind \
71+
bitcoin-cli -regtest -rpcconnect=127.0.0.1 -rpcport=43782 -rpcuser=polaruser -rpcpassword=polarpass \
72+
sendtoaddress "$LND_ADDRESS" "$FUND_BTC" >/dev/null
73+
74+
MINER_ADDRESS="$(
75+
docker compose -f "$COMPOSE_FILE" exec -T bitcoind \
76+
bitcoin-cli -regtest -rpcconnect=127.0.0.1 -rpcport=43782 -rpcuser=polaruser -rpcpassword=polarpass \
77+
getnewaddress
78+
)"
79+
docker compose -f "$COMPOSE_FILE" exec -T bitcoind \
80+
bitcoin-cli -regtest -rpcconnect=127.0.0.1 -rpcport=43782 -rpcuser=polaruser -rpcpassword=polarpass \
81+
generatetoaddress 1 "$MINER_ADDRESS" >/dev/null
82+
83+
echo
84+
echo "External channel connection data:"
85+
echo "id: $LND_NODE_ID"
86+
echo "host: $HOST"
87+
echo "port: $PORT"
88+
echo "uri: ${LND_NODE_ID}@${HOST}:${PORT}"
89+
echo
90+
echo "Manual app flow:"
91+
echo "Settings -> Advanced -> Channels -> Add -> Manual"
92+
echo
93+
echo "lnd remains online after this script exits."

0 commit comments

Comments
 (0)