Skip to content

Commit 17137fe

Browse files
committed
feat(bin): Add network initialization script
1 parent d733b50 commit 17137fe

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

bin/network-init.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
test -z "${2}" && echo "USAGE: ${0} <network_id> <file://build.yml> [data dir]" && exit 1
4+
5+
network_id=${1}
6+
network_build=${2}
7+
dir=${3:-/tmp}
8+
socket=${dir}/appchain.sock
9+
10+
cat <<EOF
11+
Initialize Network:
12+
data directory: '${dir}'
13+
network id: '${network_id}'
14+
network build file: '${network_build}'
15+
EOF
16+
17+
mkdir -p "${dir}"
18+
19+
node \
20+
--experimental-specifier-resolution=node \
21+
--experimental-vm-modules \
22+
--experimental-wasm-modules \
23+
--experimental-wasm-threads \
24+
--no-warnings \
25+
dist/index.js \
26+
--admin \
27+
--debug \
28+
--ipfs \
29+
--ipfs-data ${dir}/ipfs \
30+
--key ${dir}/admin.key \
31+
--listen \
32+
--nonce \
33+
--socket ${socket} \
34+
--tx-status-retries 0 \
35+
&
36+
PID=$!
37+
38+
# Wait for the socket to exist
39+
while [ ! -S ${socket} ]; do sleep 1; done
40+
41+
appchain () {
42+
echo "$@" | tee >(cat >&2) | nc -U -q 0 ${socket}
43+
sleep 0.2s
44+
}
45+
46+
appchain admin setAdmin
47+
appchain nodes setRegistrationStake 0
48+
appchain nodes openRegistration
49+
appchain networks register ${network_id} ${network_build}
50+
sleep 1s # avoid nonce collision from slower register command (IPFS)
51+
appchain networks setActive ${network_id}
52+
53+
kill ${PID}
54+
55+
rm -f ${socket}

0 commit comments

Comments
 (0)