-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker_regtest_setup.sh
executable file
·118 lines (103 loc) · 3.02 KB
/
docker_regtest_setup.sh
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
113
114
115
116
117
118
#!/usr/bin/env bash
CONFIG_FILE="config.py"
DATA_DIR="faucet_data"
SERVICE_DIR="service_data"
COMPOSE="docker compose"
BCLI="$COMPOSE exec -T -u blits bitcoind bitcoin-cli -regtest"
COMPOSE_EXEC="docker compose exec -T faucet bash -lc"
_tit() {
echo
echo "========================================"
echo "$@"
echo "========================================"
}
# build the faucet image
_tit "building docker image"
$COMPOSE build
# avoid overwriting an existing config file
_tit "performing initial checks"
if [ -r "$CONFIG_FILE" ] || [ -r "$DATA_DIR" ] || [ -r "$SERVICE_DIR" ]; then
read -rp "existing data found, remove and continue? [y/N] " ans
case $ans in
y|Y)
rm -r $CONFIG_FILE $DATA_DIR
docker run --rm -v "$(pwd)":/data debian:bookworm \
bash -c "rm -r /data/$SERVICE_DIR"
;;
n|N)
echo "aborting"
exit 2
;;
*)
echo "unrecognized answer"
exit 1
;;
esac
else
echo "all good"
fi
# initialize config file and data dirs
_tit "initializing the configuration file"
cat > $CONFIG_FILE <<EOF
NAME = "regtest faucet"
DATA_DIR = "/home/faucet/data"
NETWORK = "regtest"
ELECTRUM_URL = "tcp://electrs:50001"
CONSIGNMENT_ENDPOINTS = ['rpc:proxy:3000/json-rpc']
EOF
mkdir $DATA_DIR
chown 1000:1000 $DATA_DIR
_tit "initializing the wallet"
res="$($COMPOSE run --no-deps --rm -T faucet bash -lc "poetry run wallet-helper --init")"
mnemonic=$(echo "$res" |awk -F':' '/mnemonic/ {print $2}' | xargs)
xpub=$(echo "$res" |awk '/xpub/ {print $NF}')
cat >> $CONFIG_FILE <<EOF
MNEMONIC = "$mnemonic"
XPUB = "$xpub"
EOF
_tit "starting services"
docker compose down -v
$COMPOSE up -d electrs
# wait for bitcoind to be up
until $COMPOSE logs bitcoind |grep 'Bound to'; do
sleep 1
done
# prepare bitcoin funds
$BCLI createwallet miner
$BCLI -rpcwallet=miner -generate 111
# wait for electrs to have completed startup
until $COMPOSE logs electrs |grep 'finished full compaction'; do
sleep 1
done
# run a sleeping faucet container
faucet_container="$($COMPOSE run --no-deps -d faucet sleep 999)"
_tit "funding the wallet"
res="$($COMPOSE_EXEC "poetry run wallet-helper --address")"
address=$(echo "$res" |awk '/address:/ {print $NF}')
$BCLI -rpcwallet=miner sendtoaddress "$address" 1
$BCLI -rpcwallet=miner -generate 1
_tit "issuing and configuring an RGB asset"
res="$($COMPOSE_EXEC "poetry run issue-asset NIA 'fungible token' 0 1000 --ticker 'FFA' --unattended")"
asset_id=$(echo "$res" |awk '/asset ID:/ {print $NF}')
cat >> $CONFIG_FILE <<EOF
ASSETS = {
'group': {
'label': 'asset group',
'distribution': {
'mode': 1,
},
'assets': [
{
'asset_id': '$asset_id',
'amount': 3,
},
]
},
}
EOF
_tit "stopping the services"
docker rm -f -v "$faucet_container"
docker compose down -v
_tit "setup complete"
echo "the regtest faucet is now ready"
echo "(start services with 'docker compose up -d')"