Skip to content

Instantly share code, notes, and snippets.

@mutatrum
Last active September 14, 2022 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutatrum/98c60073c76fb4f742ed007ea6f941af to your computer and use it in GitHub Desktop.
Save mutatrum/98c60073c76fb4f742ed007ea6f941af to your computer and use it in GitHub Desktop.
Print all historical difficulty adjustments
#!/bin/bash
CURRENTHEIGHT=$(bitcoin-cli getblockchaininfo | jq -r .blocks)
DIFFICULTY=1
for ((HEIGHT = 0 ; HEIGHT < CURRENTHEIGHT ; HEIGHT += 2016))
do
NEW_DIFFICULTY=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $HEIGHT) | jq -r .difficulty)
ADJUSTMENT=$(bc <<< "scale=16 ; ((($NEW_DIFFICULTY * 100 / $DIFFICULTY)) - 100)" | awk '{printf("%.2f \n",$1)}')
echo $((HEIGHT / 2016)) $HEIGHT $NEW_DIFFICULTY $ADJUSTMENT
DIFFICULTY=$NEW_DIFFICULTY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment