-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathwait-for-mirror-node.sh
executable file
·69 lines (55 loc) · 1.82 KB
/
wait-for-mirror-node.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
#!/bin/bash
set -euo pipefail
CI=${CI:-false}
if [[ "$CI" = "true" ]]; then
sleep 30
else
sleep 5
fi
network_identifier=""
echo "Waiting for Mirror Node to start syncing"
while true;
do
response="$(curl -sL -w "%{http_code}" -d '{"metadata":{}}' -i "http://localhost:5700/network/list")"
http_code="$(tail -n1 <<< "${response}")"
if [[ "${http_code}" = "200" ]]; then
echo "Mirror Node has started initialising"
network_identifier=$(tail -n2 <<< "$response" | head -n1 | jq '.network_identifiers[0]')
break
fi
sleep 1
done
if [[ -z "${network_identifier}" ]]; then
echo "Rosetta Network Identifier has not been provided"
echo "Exiting"
exit 1
fi
SECONDS=0
max_wait_seconds=${MAX_WAIT_SECONDS:-120}
while [[ "${SECONDS}" -lt "${max_wait_seconds}" ]];
do
body="{ \"network_identifier\": ${network_identifier}, \"metadata\": {} }"
response=$(curl -sL -w "%{http_code}" -d "${body}" -i "http://localhost:5700/network/status")
http_code=$(tail -n1 <<< "${response}")
if [[ "${http_code}" = "200" ]]; then
current_block_index=$(tail -n2 <<< "${response}" | head -n1 | jq '.current_block_identifier.index')
if [[ "$current_block_index" != "0" ]]; then
echo "Mirror Node syncing has started"
exit 0
else
echo "Mirror Node syncing has not started yet"
fi
else
echo "Mirror Node syncing has not started yet"
response_body="$(tail -n2 <<< "${response}" | head -n1)"
retryable="$(echo "${response_body}" | jq '.retriable')"
if [[ "${retryable}" = false ]]; then
echo "Request cannot be retried, response body: ${response_body}"
echo "Exiting"
exit 1
fi
fi
sleep 5
done
echo "Timed out while waiting for the mirror node"
exit 1