Skip to content

Instantly share code, notes, and snippets.

@bb111189
Forked from nnamon/zildiff.py
Created February 7, 2019 13:11
Show Gist options
  • Save bb111189/3c3cc4b16b09913d157d55aa85044921 to your computer and use it in GitHub Desktop.
Save bb111189/3c3cc4b16b09913d157d55aa85044921 to your computer and use it in GitHub Desktop.
Zilliqa Difficulty Calculations
def to_boundary(diff):
b = ["1"] * 256
for i in range(diff):
b[i] = "0"
return int("".join(b), 2)
def to_hashrate(diff):
boundary = to_boundary(diff)
result = pow(2, 256) / float(boundary)
return result
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment