-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwaves-scripts
executable file
·166 lines (123 loc) · 3.27 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
#!/bin/bash
start_dev_env () {
set -e
start_nodes
load_native_asset
mint_usdt
start_bobtimus
start_frontend
}
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
}
mint_usdt () {
set -e
local -r amount=1000000
address=$(nigiri rpc --liquid getnewaddress)
# need to wait a couple of seconds so that we don't fail on the second request
sleep 2
response=$(nigiri mint $address $amount "Tether USD" "USDt")
usdt_asset_id=$(echo $response | sed -n -e 's/^.*\(asset: \)\(.*\)\( issuance_txin: .*$\)/\2/p')
# 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
}
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 fake_bobtimus
local -r elementsd_rpc_user="admin1"
local -r elementsd_rpc_password="123"
RUST_LOG=debug cargo run --bin fake_bobtimus -- \
--elementsd http://$elementsd_rpc_user:[email protected]:$LIQUID_NODE_PORT \
--usdt $usdt_asset_id > $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_frontend () {
set -e
if [ ! -f ".native_asset_id" ]; then
echo "Native asset id not configured."
exit 1
fi
__read_env_file
cd waves
yarn install
export NATIVE_ASSET_ID=$(cat ../.native_asset_id)
export USDT_ASSET_ID=$(cat ../.usdt_asset_id)
export CHAIN=ELEMENTS
export ESPLORA_API_URL=$LIQUID_ESPLORA_URL
export REACT_APP_BLOCKEXPLORER_URL="http://localhost:$LIQUID_ESPLORA_PORT"
yarn start
}
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
}
"$@"