-
Notifications
You must be signed in to change notification settings - Fork 9
/
connect
executable file
·53 lines (44 loc) · 1.57 KB
/
connect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
set -e -o pipefail
source _toolbox_lib.sh
FROM_PERSON=${1:-alice}
TO_PERSON=${2:-bob}
connect_bitcoin_nodes() {
local role
role=$(get_role "$TO_PERSON")
if [[ "$role" != "bitcoin" ]]; then
echo_err "both nodes to have the same role, '$TO_PERSON' has role '$role' but 'bitcoin' was expected"
exit 2
fi
# note: we don't have to check for flavor here, both bitcoind and btcd have compatible 'addnode' cli interface
"$FROM_PERSON" addnode "$TO_PERSON" onetry
# note we need to generate one block to trigger potential block sync
# not sure what is the issue, but this might be related https://bitcoin.stackexchange.com/q/27055/875
generate 1 "$FROM_PERSON"
}
connect_ln_nodes() {
local role
role=$(get_role "$TO_PERSON")
if [[ "$role" != "ln" ]]; then
echo_err "both nodes to have the same role, '$TO_PERSON' has role '$role' but 'ln' was expected"
exit 2
fi
TO_PERSON_CONNECTION=$(ln_connect_string "$TO_PERSON")
if [[ -z "$TO_PERSON_CONNECTION" ]]; then
echo_err "failed to format connection string for '$TO_PERSON'"
exit 1
fi
local flavor
flavor=$(get_flavor "$FROM_PERSON")
case "$flavor" in
lnd|lightning) "$FROM_PERSON" connect "$TO_PERSON_CONNECTION" ;;
eclair) "$FROM_PERSON" connect --uri="$TO_PERSON_CONNECTION" ;;
*) echo_err "unsupported flavor type '$flavor' for '$FROM_PERSON'"; exit 1; ;;
esac
}
ROLE=$(get_role "$FROM_PERSON")
case "$ROLE" in
bitcoin) connect_bitcoin_nodes ;;
ln) connect_ln_nodes ;;
*) echo_err "unsupported role type '$ROLE' for '$FROM_PERSON'"; exit 1; ;;
esac