Files
universe/scripts/check-tracked-chains.sh

51 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
network="${1:-}"
http_port="${2:-}"
if [[ -z "${network}" || -z "${http_port}" ]]; then
echo "usage: $0 <network> <http-port>" >&2
exit 1
fi
case "${network}" in
mainnet)
entries=("zoo:zoo" "hanzo:hanzo" "spc:spc" "pars:pars")
;;
testnet)
entries=("zoo:zootest" "hanzo:hanzotest" "spc:spctest" "pars:parstest")
;;
devnet)
entries=("zoo:zoo" "hanzo:hanzo" "spc:spc" "pars:pars")
;;
*)
echo "unsupported network: ${network}" >&2
exit 1
;;
esac
echo " Tracked chains:"
for pair in "${entries[@]}"; do
label="${pair%%:*}"
bc_id="${pair##*:}"
raw="$(curl -s -m 1 -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
"http://127.0.0.1:${http_port}/v1/chain/${bc_id}/rpc" 2>/dev/null || true)"
block="$(jq -r '.result // empty' <<<"${raw}" 2>/dev/null || true)"
if [[ -n "${block}" && "${block}" =~ ^0x[0-9a-fA-F]+$ ]]; then
dec=$((16#${block#0x}))
printf " %-6s %s (%s)\n" "${label}:" "${block}" "${dec}"
continue
fi
msg="$(jq -r '.error.message // empty' <<<"${raw}" 2>/dev/null || true)"
if [[ -n "${msg}" ]]; then
printf " %-6s offline (%s)\n" "${label}:" "${msg}"
else
printf " %-6s offline\n" "${label}:"
fi
done