-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstartRegtest.sh
More file actions
executable file
·112 lines (82 loc) · 3.05 KB
/
startRegtest.sh
File metadata and controls
executable file
·112 lines (82 loc) · 3.05 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
set -euo pipefail
bitcoin_container='boltz-bitcoin'
bitcoin_config='--conf=/config/bitcoin.conf'
elements_container='boltz-elements'
elements_config='--conf=/config/elements.conf'
bitcoin_rpc=(bitcoin-cli --regtest -rpcuser=kek -rpcpassword=kek)
elements_rpc=(elements-cli -chain=liquidregtest -rpcport=18884 -rpcuser=elements -rpcpassword=elements)
print_header() {
echo "------"
echo "Starting $1"
echo "------"
echo ""
}
config_mount() {
local mount_mode='ro'
if command -v getenforce >/dev/null 2>&1; then
local selinux_status
selinux_status="$(getenforce 2>/dev/null || true)"
if [ -n "$selinux_status" ] && [ "$selinux_status" != "Disabled" ]; then
mount_mode="${mount_mode},Z"
fi
fi
printf '%s/docker:/config:%s' "$(pwd)" "$mount_mode"
}
cleanup_container() {
docker rm -f "$1" >/dev/null 2>&1 || true
}
show_logs() {
echo ""
echo "Container logs for $1:"
docker logs "$1" 2>&1 || true
}
wait_for_rpc() {
local container="$1"
local service_name="$2"
shift 2
local attempts=60
while [ "$attempts" -gt 0 ]; do
if docker exec "$container" "$@" >/dev/null 2>&1; then
return 0
fi
if ! docker ps --format '{{.Names}}' | grep -Fxq "$container"; then
echo "$service_name exited before becoming ready" >&2
show_logs "$container" >&2
exit 1
fi
attempts=$((attempts - 1))
sleep 1
done
echo "Timed out waiting for $service_name RPC" >&2
show_logs "$container" >&2
exit 1
}
mount_path="$(config_mount)"
print_header "Bitcoin Core"
echo "Resetting container"
cleanup_container "$bitcoin_container"
echo "Creating container"
docker run -d --name "$bitcoin_container" -v "$mount_path" -p 18443:18443 boltz/bitcoin-core:30.2 "$bitcoin_config" > /dev/null
echo "Waiting for RPC"
wait_for_rpc "$bitcoin_container" "Bitcoin Core" "${bitcoin_rpc[@]}" getblockchaininfo
echo "Creating wallet"
docker exec "$bitcoin_container" "${bitcoin_rpc[@]}" createwallet default > /dev/null
echo ""
print_header "Elements Core"
echo "Resetting container"
cleanup_container "$elements_container"
echo "Creating container"
docker run -d --name "$elements_container" -v "$mount_path" -p 18884:18884 boltz/elements:23.3.2 "$elements_config" > /dev/null
echo "Waiting for RPC"
wait_for_rpc "$elements_container" "Elements Core" "${elements_rpc[@]}" getblockchaininfo
echo "Creating wallet"
docker exec "$elements_container" "${elements_rpc[@]}" createwallet default > /dev/null
echo "Generating block"
docker exec "$elements_container" "${elements_rpc[@]}" -generate 1 > /dev/null
echo "Rescanning the chain"
docker exec "$elements_container" "${elements_rpc[@]}" rescanblockchain > /dev/null
echo "Creating output"
address="$(docker exec "$elements_container" "${elements_rpc[@]}" getnewaddress "" blech32)"
docker exec "$elements_container" "${elements_rpc[@]}" sendtoaddress "$address" 1 > /dev/null
docker exec "$elements_container" "${elements_rpc[@]}" -generate 1 > /dev/null