forked from nanocurrency/generate-epoch-blocks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish-blocks.sh
executable file
·36 lines (33 loc) · 1.16 KB
/
publish-blocks.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
#!/bin/bash
set -eu
if [ $# -lt 4 ]; then
echo "Usage: publish-blocks.sh blocks-inner blocks-work blocks-signatures <RPC URL> [publish delay] [offset]" >&2
exit 1
fi
i=0
offset="${6:-0}"
while IFS='' read -r blockInner <&11 && IFS='' read -r work <&12 && IFS='' read -r signature <&13; do
if [ "$offset" -gt 0 ]; then
offset=$(("$offset"-1))
continue
fi
rpcCall="$(jq -nc --argjson blockInner "$blockInner" --arg work "$work" --arg signature "$signature" \
'$blockInner * { "work": $work } * { "signature": $signature }
| tostring
| { "action": "process", "block": . }')"
rpcResult="$(curl -s --show-error "$4" -d "$rpcCall")"
error="$(jq -er .error <(echo "$rpcResult"))"
if [ "$error" = "Fork" ]; then
echo
echo "Encountered a fork for account $(echo "$blockInner" | jq -r .account)" >&2
elif [ "$error" != "Old block" ]; then
continue
elif [ "$error" != "null" ]; then
echo
echo "Encountered unexpected error '$error' from RPC call $rpcCall" >&2
exit 2
fi
i=$(($i+1))
printf "\r$i"
sleep "${5:-0.1}"
done 11<"$1" 12<"$2" 13<"$3"