#!/usr/bin/env bash # verify-tx.sh — poll for tx inclusion, extract event attributes, surface common needs. # # Useful after instantiate-subdao.sh or propose-bank-send.sh — captures the # follow-up data (contract addresses for instantiates, proposal_id for proposals) # without writing ad-hoc jq each time. # # Usage: # verify-tx.sh --txhash [--rpc ] [--timeout 30] # # Block time on Juno is ~5–6s. Default timeout is 30s (5–6 polls); raise for slow nodes. set -euo pipefail TXHASH="" RPC="https://juno-rpc.publicnode.com:443" TIMEOUT=30 while [ $# -gt 0 ]; do case "$1" in --txhash) TXHASH="$2"; shift 2 ;; --rpc) RPC="$2"; shift 2 ;; --timeout) TIMEOUT="$2"; shift 2 ;; -h|--help) sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "unknown flag: $1" >&2; exit 1 ;; esac done if [ -z "$TXHASH" ]; then echo "missing required: --txhash" >&2 exit 1 fi DEADLINE=$(( $(date +%s) + TIMEOUT )) RESULT="" while [ "$(date +%s)" -lt "$DEADLINE" ]; do if RESULT=$(junod query tx "$TXHASH" --node "$RPC" -o json 2>/dev/null); then break fi sleep 3 done if [ -z "$RESULT" ]; then echo "tx $TXHASH not found within ${TIMEOUT}s — either rejected at CheckTx (re-broadcast and read the immediate response) or RPC is lagging" >&2 exit 1 fi CODE=$(echo "$RESULT" | jq -r '.code // 0') HEIGHT=$(echo "$RESULT" | jq -r '.height') GAS_USED=$(echo "$RESULT" | jq -r '.gas_used') RAW_LOG=$(echo "$RESULT" | jq -r '.raw_log') echo "==> tx $TXHASH" echo " height: $HEIGHT" echo " code: $CODE" echo " gas_used: $GAS_USED" if [ "$CODE" != "0" ]; then echo " FAILED: raw_log: $RAW_LOG" exit 2 fi # Contract addresses from instantiate events (if any) ADDRS=$(echo "$RESULT" | jq -r '.events[]? | select(.type == "instantiate") | .attributes[]? | select(.key == "_contract_address") | .value') if [ -n "$ADDRS" ]; then echo " _contract_addresses (in instantiate-event order):" echo "$ADDRS" | while read -r a; do echo " - $a"; done fi # proposal_id from wasm events (if any) PROP_IDS=$(echo "$RESULT" | jq -r '.events[]? | select(.type == "wasm") | .attributes[]? | select(.key == "proposal_id") | .value' | sort -u) if [ -n "$PROP_IDS" ]; then echo " proposal_id(s) emitted:" echo "$PROP_IDS" | while read -r p; do echo " - $p"; done fi # Transfer events (if any) — useful for bank.send confirmation TRANSFERS=$(echo "$RESULT" | jq -r '.events[]? | select(.type == "transfer") | .attributes // [] | " \([.[] | select(.key == "sender") | .value] | first) → \([.[] | select(.key == "recipient") | .value] | first): \([.[] | select(.key == "amount") | .value] | first)"') if [ -n "$TRANSFERS" ]; then echo " transfers:" echo "$TRANSFERS" fi # Code IDs from store_code events (if any) CODE_IDS=$(echo "$RESULT" | jq -r '.events[]? | select(.type == "store_code") | .attributes[]? | select(.key == "code_id") | .value') if [ -n "$CODE_IDS" ]; then echo " code_id(s) stored:" echo "$CODE_IDS" | while read -r c; do echo " - $c"; done fi # Always print the explorer URL echo " explorer: https://www.mintscan.io/juno/tx/$TXHASH"