Last active
June 29, 2021 11:27
-
-
Save mutatrum/2a71c8e852b37a549c69c7027ac6ac98 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)) | |
STARTHEIGHT=$((CURRENTHEIGHT-BLOCKS)) | |
STARTBLOCK=$(bitcoin-cli getblock $(bitcoin-cli getblockhash $STARTHEIGHT)) | |
STARTTIME=$(echo $STARTBLOCK | jq -r .mediantime) | |
AVERAGETIME=$(((CURRENTTIME-STARTTIME)/BLOCKS)) | |
PERCENT=$(awk "BEGIN {print -100+(60000/$AVERAGETIME)}") | |
REMAININGBLOCKS=$((2016-BLOCKS)) | |
ENDTIME=$((CURRENTTIME+(AVERAGETIME*REMAININGBLOCKS))) | |
DATE=$(date -d @$ENDTIME +'%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