Last active
June 29, 2021 11:27
-
-
Save mutatrum/f9a8880ec6613d213fd7da17c6a6852e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo) | |
CURRENTHEIGHT=$(echo $BLOCKCHAININFO | jq -r .blocks) | |
CURRENTTIME=$(echo $BLOCKCHAININFO | jq -r .mediantime) | |
BLOCKS=$((CURRENTHEIGHT%2016)) | |
REMAINING=$((2016-BLOCKS)) | |
LOOKBACKHEIGHT=$((CURRENTHEIGHT-REMAINING)) | |
LOOKBACKBLOCK=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $LOOKBACKHEIGHT)) | |
LOOKBACKTIME=$(echo $LOOKBACKBLOCK | jq -r .mediantime) | |
LOOKBACKDELTA=$((CURRENTTIME-LOOKBACKTIME)) | |
TARGETTIME=$((CURRENTTIME+LOOKBACKDELTA)) | |
STARTHEIGHT=$((CURRENTHEIGHT-BLOCKS)) | |
STARTBLOCK=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $STARTHEIGHT)) | |
STARTTIME=$(echo $STARTBLOCK | jq -r .mediantime) | |
TOTALTIME=$((TARGETTIME-STARTTIME)) | |
AVERAGETIME=$((TOTALTIME/2016)) | |
PERCENT=$(awk "BEGIN {print -100+(60000/$AVERAGETIME)}") | |
DATE=$(date -d @$TARGETTIME +'%Y-%m-%d %H:%M') | |
echo Difficulty adjustment: $PERCENT% on $DATE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment