Skip to content

Instantly share code, notes, and snippets.

@harding
Created November 30, 2023 14:07
Show Gist options
  • Save harding/4c1f734580afe8dd5151ce60b4c31762 to your computer and use it in GitHub Desktop.
Save harding/4c1f734580afe8dd5151ce60b4c31762 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
## Year with the final blocks we want to check.
## Replace with "2024" for market
YEAR=2022
## Block to start scanning backwards from. Replace with "" (empty) to
## scan all blocks. Use "" (empty) for market
START_BLOCK="770000"
year_epoch=$( date -d "$YEAR-12-31" +%s )
## Get block to start scanning backwards from
if [ "$START_BLOCK" ] ; then
hash=$( bitcoin-cli getblockhash $START_BLOCK )
else
hash=$( bitcoin-cli getbestblockhash )
fi
past_blocks_checked=0
until [ $( bitcoin-cli getblock $hash | jq .time ) -lt $year_epoch ]; do
echo -n .
hash=$( bitcoin-cli getblock $hash | jq -r .previousblockhash )
past_blocks_checked=$(( past_blocks_checked + 1 ))
done
echo
echo "Blocks checked (must be >30 to settle market): $past_blocks_checked"
echo "Hash of last block in $YEAR: $hash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment