#!/bin/bash set -euo pipefail # Reads stdin or the file $1, looks lines up as hashes, then outputs block info # for each hash. Uses the zcash-cli command for block lookups. ZEBRAD="${ZEBRAD:-zebrad}" ZCASH_CLI="${ZCASH_CLI:-zcash-cli}" while read hash; do zcashd_hash=$($ZEBRAD revhex "$hash") header=$($ZCASH_CLI getblockheader "$zcashd_hash" 2>&1 || true) if echo "$header" | jq . > /dev/null 2> /dev/null; then high=$(echo "$header" | jq -r '"\(.height)"') time=$(echo "$header" | jq -r '"\(.time|todate)"') prev=$(echo "$header" | jq -r '"\(.previousblockhash)"') next=$(echo "$header" | jq -r '"\(.nextblockhash)"') # use Zebra hash order if [ "$prev" != 'null' ]; then prev=$($ZEBRAD revhex "$prev") fi if [ "$next" != 'null' ]; then next=$($ZEBRAD revhex "$next") fi printf 'high: %s\ntime: %s\nhash: %s\nprev: %s\nnext: %s\n' \ "$high" "$time" "$hash" "$prev" "$next" else # Handle lookup errors printf 'hash: %s\n%s\n' \ "$hash" "$header" fi done < "${1:-/dev/stdin}"