Last active
March 21, 2020 01:32
-
-
Save JBaczuk/c203c1934d9c642c27c5210362e890a3 to your computer and use it in GitHub Desktop.
Bitcoin Network Hashrate
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
#!/usr/bin/env python | |
import sys | |
# Get command line arguments | |
########################## | |
# Note this script will calculate based on an average of 1 day's worth of blocks | |
if len(sys.argv) < 2: | |
print "Usage: $ btc_hashrate <blocks-24h> <current-difficulty>" | |
sys.exit() | |
actualBlocks = float(sys.argv[1]) | |
currentDifficulty = float(sys.argv[2]) | |
# Math | |
########################## | |
blockTime = 10.0 # minutes | |
minutesPerDay = 24.0 * 60.0 | |
expectedBlocks = minutesPerDay / 10.0 # 144 (1 days worth of blocks) | |
secondsPerBlock = 60.0 * 10.0 # 60 seconds * 10 minutes | |
hashpower = (actualBlocks / expectedBlocks) * (currentDifficulty * 2**32) / secondsPerBlock | |
# Print it nicely | |
if hashpower < 1000 * 1e9: | |
print hashpower/1e9, "GH/s (1e9)" | |
elif hashpower < 1000 * 1e12: | |
print hashpower/1e12, "TH/s (1e12)" | |
elif hashpower < 1000 * 1e15: | |
print hashpower/1e15, "PH/s (1e15)" | |
elif hashpower < 1000 * 1e18: | |
print hashpower/1e18, "EH/s (1e18)" | |
else: | |
print hashpower/1e21, "ZH/s (1e21)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @ashraful1980, just needed a
sys.exit()