Last active
February 10, 2019 07:58
-
-
Save nnamon/e60f8c2ec15731a2f1ab853e57f2cf5e to your computer and use it in GitHub Desktop.
Zilliqa Difficulty Calculations
This file contains 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
POW_WINDOW = 60 | |
def to_boundary(diff): | |
b = ["1"] * 256 | |
for i in range(diff): | |
b[i] = "0" | |
return int("".join(b), 2) | |
def to_hashes(diff): | |
boundary = to_boundary(diff) | |
result = pow(2, 256) / float(boundary) | |
return result | |
def to_hashrate(diff): | |
return to_hashes(diff)/POW_WINDOW | |
def abbrev_hashrate(rate): | |
quantifiers = (("Gh", 1000000000.0), ("Mh", 1000000.0), ("Kh", 1000.0)) | |
for quant, divisor in quantifiers: | |
divided = rate/divisor | |
if divided > 1: | |
return "%.f %s" % (divided, quant) | |
return "%d H" % rate | |
def hashrate_required(diff): | |
print(abbrev_hashrate(to_hashrate(diff))) | |
hashrate_required(31) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment