-
Notifications
You must be signed in to change notification settings - Fork 6
/
waves-scripts
executable file
·216 lines (157 loc) · 4.02 KB
/
waves-scripts
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
start_webapp_dev_env () {
set -e
start_nodes
load_native_asset
mint_usdt
start_bobtimus
start_webapp
}
start_extension_dev_env () {
set -e
start_nodes
load_native_asset
mint_usdt
build_webapp
start_bobtimus
}
stop_dev_env () {
stop_nodes
stop_bobtimus
}
start_nodes () {
set -e
# start elementsd, esplora (et al)
nigiri start --liquid
# wait for everything to be started up
sleep 2
}
load_native_asset () {
# get native asset ID.
local native_asset_id=$(nigiri rpc --liquid dumpassetlabels | jq -r '.bitcoin')
if [ "$native_asset_id" = "null" ]; then
echo "Bitcoin asset id not found."
exit 1
fi
echo "NATIVE_ASSET_ID=$native_asset_id"
echo "$native_asset_id" > .native_asset_id
}
mint_usdt () {
set -e
local -r amount=1000000
usdt_asset_id=$(docker exec liquid elements-cli -rpcuser=admin1 -rpcpassword=123 -rpcport=18884 issueasset $amount 1 | jq -r '.asset')
# mine a block
address=$(nigiri rpc --liquid getnewaddress)
docker exec liquid elements-cli -rpcuser=admin1 -rpcpassword=123 -rpcport=18884 generatetoaddress 1 $address &> /dev/null
# get usdt asset ID.
if [ "$usdt_asset_id" = "null" ]; then
echo "Usdt asset id not found."
exit 1
fi
echo "USDT_ASSET_ID=$usdt_asset_id"
echo "$usdt_asset_id" > .usdt_asset_id
}
start_bobtimus () {
if [ -f ".bobtimus" ]; then
echo "Are you sure Bobtimus is not already up?"
exit 1
fi
if [ ! -f ".usdt_asset_id" ]; then
echo "Usdt asset id not configured. Did you run mint_usdt?"
exit 1
fi
usdt_asset_id=$(cat .usdt_asset_id)
set -e
__ensure_log_dir
__read_env_file
cargo build --bin bobtimus --features faucet
local -r elementsd_rpc_user="admin1"
local -r elementsd_rpc_password="123"
RUST_LOG=debug,hyper=info,reqwest=info cargo run --bin bobtimus --features faucet -- \
start \
--http 127.0.0.1:3030 \
--elementsd http://$elementsd_rpc_user:[email protected]:$LIQUID_NODE_PORT \
--usdt $usdt_asset_id \
--db-file="./.bobtimus.sqlite" > $log_dir/bobtimus 2>&1 &
bobtimus_pid=$!
sleep 1
curl --fail http://127.0.0.1:3030 &> /dev/null
if [ $? -ne 0 ]; then
set +e
pkill bobtimus_pid
set -e
echo "Failed to start Bobtimus"
exit 1
fi
# save bobtimus pid to file for future teardown
echo $bobtimus_pid > .bobtimus
echo "Started bobtimus with pid $bobtimus_pid"
}
start_webapp () {
set -e
build_webapp
cd waves
yarn run start
}
build_webapp () {
set -e
__read_env_file
cd waves
yarn install
export REACT_APP_BLOCKEXPLORER_URL="http://localhost:$LIQUID_ESPLORA_PORT"
yarn run build
cd ..
}
start_extension () {
set -e
cd extension
yarn run dev
}
build_extension () {
set -e
if [ ! -f ".native_asset_id" ]; then
echo "Native asset id not configured."
exit 1
fi
__read_env_file
cd extension
yarn install
export NATIVE_ASSET_ID=$(cat ../.native_asset_id)
export USDT_ASSET_ID=$(cat ../.usdt_asset_id)
export CHAIN=ELEMENTS
echo "export NATIVE_ASSET_ID=$NATIVE_ASSET_ID"
echo "export USDT_ASSET_ID=$USDT_ASSET_ID"
echo "export CHAIN=$CHAIN"
yarn run build
cd ..
}
stop_nodes () {
nigiri stop --delete
rm .native_asset_id
rm .usdt_asset_id
}
stop_bobtimus () {
bobtimus_pid=$(cat .bobtimus)
if [ $? -ne 0 ]; then
echo "Are you sure Bobtimus is still running?"
exit 1
fi
kill -9 $bobtimus_pid
echo "Terminated bobtimus with pid $bobtimus_pid"
if [ $? -ne 0 ]; then
echo "Bobtimus is not running"
fi
rm .bobtimus
}
restart_bobtimus () {
stop_bobtimus
start_bobtimus
}
__read_env_file () {
export $(cat ~/.nigiri/.env | xargs)
}
__ensure_log_dir () {
readonly log_dir="./.log"
mkdir -p $log_dir
}
"$@"