Files
proxmox/scripts/verify/xdc-zero-chain138-preflight.sh
defiQUG 6390174bb7 feat(xdc-zero): Chain 138 bridge runbook, config fragments, merge helper
- Add CHAIN138_XDC_ZERO_BRIDGE_RUNBOOK and 07-ccip pointer doc
- Add config/xdc-zero templates, parent register fragment, README
- Add merge-endpointconfig-chain138.sh (jq merge, XDC_ZERO_ENDPOINT_DIR)
- Add xdc-zero-chain138-preflight.sh; trim XDC URL vars in load-project-env
- Wire AGENTS.md, MASTER_INDEX, verify README, .env.master.example

Made-with: Cursor
2026-03-31 23:10:36 -07:00

75 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Preflight: RPC reachability and eth_chainId for XDC Zero second pair (parent ↔ Chain 138).
# Optional: ETHEREUM_MAINNET_RPC (or other vars) for quick public mainnet access checks.
#
# Usage:
# bash scripts/verify/xdc-zero-chain138-preflight.sh
# XDC mainnet (default in .env.master.example): XDC_PARENTNET_URL=https://rpc.xinfin.network
# Apothem: XDC_PARENTNET_URL=https://rpc.apothem.network bash scripts/verify/xdc-zero-chain138-preflight.sh
#
# Loads repo dotenv via scripts/lib/load-project-env.sh when sourced from repo root.
# Avoid nounset while sourcing dotenv (some .env lines reference optional vars).
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# shellcheck source=/dev/null
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh"
_rpc_chain_id() {
local url="$1"
local name="$2"
if [[ -z "$url" || "$url" == "devnet" || "$url" == "testnet" ]]; then
echo "SKIP $name: empty or alias URL ($url) — resolve to HTTPS RPC for this check."
return 0
fi
local out
if ! out="$(curl -sS --connect-timeout 8 --max-time 20 -X POST "$url" \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>/dev/null)"; then
echo "FAIL $name: no HTTP response from $url"
return 1
fi
local hex
hex="$(printf '%s' "$out" | sed -n 's/.*"result":"\([^"]*\)".*/\1/p')"
if [[ -z "$hex" ]]; then
echo "FAIL $name: bad JSON or error from $url$out"
return 1
fi
echo "OK $name ($url) eth_chainId=$hex"
}
echo "=== XDC Zero Chain 138 pair — RPC preflight ==="
fail=0
PARENT="${XDC_PARENTNET_URL:-${PARENTNET_URL:-}}"
PEER="${XDC_ZERO_PEER_RPC_URL:-${RPC_URL_138:-${CHAIN138_RPC_URL:-${CHAIN138_RPC:-}}}}"
if [[ -n "$PARENT" ]]; then
_rpc_chain_id "$PARENT" "XDC_PARENTNET / PARENTNET" || fail=1
else
echo "WARN XDC_PARENTNET_URL and PARENTNET_URL unset — set one for parent checks."
fi
if [[ -n "$PEER" ]]; then
_rpc_chain_id "$PEER" "Chain138 RPC_URL_138" || fail=1
else
echo "WARN RPC_URL_138 (or CHAIN138_RPC_URL) unset — set for Chain 138 checks."
fi
if [[ -n "${ETHEREUM_MAINNET_RPC:-}" ]]; then
_rpc_chain_id "$ETHEREUM_MAINNET_RPC" "ETHEREUM_MAINNET_RPC (optional)" || fail=1
fi
if [[ -n "${BSC_RPC_URL:-}" ]]; then
_rpc_chain_id "$BSC_RPC_URL" "BSC_RPC_URL (optional)" || fail=1
fi
if [[ "$fail" -ne 0 ]]; then
echo "=== Preflight finished with failures ==="
exit 1
fi
echo "=== Preflight finished ==="
echo "Next: deploy Endpoint/CSC per docs/03-deployment/CHAIN138_XDC_ZERO_BRIDGE_RUNBOOK.md"