forked from arkade-os/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
256 lines (179 loc) · 6.04 KB
/
justfile
File metadata and controls
256 lines (179 loc) · 6.04 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
set dotenv-load
arkd_url := "http://localhost:7070"
arkd_logs := "$PWD/arkd.log"
## ------------------------
## Code quality functions
## ------------------------
fmt:
dprint fmt
clippy:
cargo clippy --all-targets --all-features -- -D warnings
# TODO: We should build `ark-core`, `ark-rest`, `ark-bdk-wallet` and eventually even `ark-client`
# for WASM.
build-wasm:
cargo build -p ark-core --target wasm32-unknown-unknown
cargo build -p ark-rest --target wasm32-unknown-unknown
## -----------------
## Code generation
## -----------------
# Generate GRPC code. Modify proto files before calling this.
gen-grpc:
#!/usr/bin/env bash
RUSTFLAGS="--cfg genproto" cargo build -p ark-grpc
## -------------------------
## Local development setup
## -------------------------
# Checkout ark (https://github.com/ark-network/ark) in a local directory
# Run with `just arkd-checkout "master"` to checkout and sync latest master or
# `just arkd-checkout "da64028e06056b115d91588fb1103021b04008ad"`to checkout a specific commit
[positional-arguments]
arkd-checkout tag:
#!/usr/bin/env bash
set -euxo pipefail
mkdir -p $ARK_GO_DIR
cd $ARK_GO_DIR
CHANGES_STASHED=false
if [ -d "ark" ]; then
# Repository exists, update it
echo "Directory exists, refreshing..."
cd ark
# Check for local changes and stash them if they exist
if ! git diff --quiet || ! git diff --staged --quiet; then
echo "Stashing local changes..."
git stash push -m "Automated stash before update"
CHANGES_STASHED=true
fi
git fetch --all
# Only update master if we're not going to check it out explicitly
if [ -z "$1" ] || [ "$1" != "master" ]; then
# Store current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Update master branch
git checkout master
git pull origin master
# Return to original branch
if [ "$CURRENT_BRANCH" != "master" ]; then
git checkout "$CURRENT_BRANCH"
fi
fi
else
echo "Directory does not exist, checking it out..."
# Clone new repository
git clone https://github.com/ark-network/ark.git
cd ark
fi
if [ ! -z "$1" ]; then
echo "Checking out " $1
git checkout $1
else
echo "Checking out master"
git checkout master
fi
# Reapply stashed changes if they exist
if [ "$CHANGES_STASHED" = true ]; then
echo "Reapplying local changes..."
git stash pop
fi
# Set up `arkd` so that we can run the client e2e tests against it.
arkd-setup:
#!/usr/bin/env bash
set -euxo pipefail
echo "Running arkd from $ARKD_DIR"
just arkd-run
echo "Started arkd"
just arkd-init
just arkd-fund 10
arkd-patch-makefile:
#!/usr/bin/env bash
set -euxo pipefail
cd ark-go/ark/server
# This version will match ARK_ROUND_INTERVAL=ANY_NUMBER
# On macOS, sed requires an empty string after -i for in-place editing
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' 's/ARK_ROUND_INTERVAL=[0-9][0-9]*/ARK_ROUND_INTERVAL=30/' Makefile
else
# Linux
sed -i 's/ARK_ROUND_INTERVAL=[0-9][0-9]*/ARK_ROUND_INTERVAL=30/' Makefile
fi
# Start `arkd` binary.
arkd-run:
#!/usr/bin/env bash
set -euxo pipefail
make -C $ARKD_DIR run &> {{arkd_logs}} &
just _wait-until-arkd-is-ready
echo "Arkd started. Find the logs in {{arkd_logs}}"
# Build `arkd` binary.
arkd-build:
#!/usr/bin/env bash
set -euxo pipefail
make -C $ARKD_DIR build
echo "Arkd built"
# Initialize `arkd` by creating and unlocking a new wallet.
arkd-init:
#!/usr/bin/env bash
set -euxo pipefail
seed=$(curl -s {{arkd_url}}/v1/admin/wallet/seed | jq .seed -r)
curl -s --data-binary '{"seed": "$seed", "password": "password"}' -H "Content-Type: application/json" {{arkd_url}}/v1/admin/wallet/create
echo "Created arkd wallet"
curl -s --data-binary '{"password" : "password"}' -H "Content-Type: application/json" {{arkd_url}}/v1/admin/wallet/unlock
echo "Unlocked arkd wallet"
just _wait-until-arkd-wallet-is-ready
# Fund `arkd`'s wallet with `n` utxos.
arkd-fund n:
#!/usr/bin/env bash
set -euxo pipefail
for i in {1..{{n}}}; do
address=$(curl -s {{arkd_url}}/v1/admin/wallet/address | jq .address -r)
echo "Funding arkd wallet (Iteration $i)"
nigiri faucet "$address" 10
done
# Stop `arkd` binary and delete logs.
arkd-kill:
pkill -9 arkd && echo "Stopped arkd" || echo "Arkd not running, skipped"
[ ! -e "{{arkd_logs}}" ] || mv -f {{arkd_logs}} {{arkd_logs}}.old
# Wipe `arkd` data directory.
arkd-wipe:
@echo Clearing arkd in $ARKD_DIR/data
rm -rf $ARKD_DIR/data
_wait-until-arkd-is-ready:
#!/usr/bin/env bash
echo "Waiting for arkd to be ready..."
for ((i=0; i<30; i+=1)); do
status_code=$(curl -o /dev/null -s -w "%{http_code}" {{arkd_url}}/v1/admin/wallet/seed)
if [ "$status_code" -eq 200 ]; then
echo "arkd is ready!"
exit 0
fi
sleep 1
done
echo "arkd was not ready in time"
exit 1
_wait-until-arkd-wallet-is-ready:
#!/usr/bin/env bash
echo "Waiting for arkd wallet to be ready..."
for ((i=0; i<30; i+=1)); do
res=$(curl -s {{arkd_url}}/v1/admin/wallet/status)
if echo "$res" | jq -e '.initialized == true and .unlocked == true and .synced == true' > /dev/null; then
echo "arkd wallet is ready!"
exit 0
fi
sleep 1
done
echo "arkd wallet was not ready in time"
exit 1
nigiri-start:
#!/usr/bin/env bash
nigiri start
nigiri-wipe:
#!/usr/bin/env bash
nigiri stop --delete
## -------------------------
## Running tests
## -------------------------
test:
@echo running all tests
cargo test -- --nocapture
e2e-tests:
@echo running e2e tests
cargo test -p e2e-tests -- --ignored --nocapture