Skip to content

Instantly share code, notes, and snippets.

@haraldschilly
Created November 25, 2012 19:49
Show Gist options
  • Save haraldschilly/4145044 to your computer and use it in GitHub Desktop.
Save haraldschilly/4145044 to your computer and use it in GitHub Desktop.
Bitcoin Blockreward Estimation
#!/usr/bin/env python
# Copyright Harald Schilly <harald.schil.ly>
# License: Apache 2.0
# Hint: run it periodically via: watch -d -n 30 python countdown.py
# (sorry blockexplorer ...)
# which halfing? 1, 2, ...
nb_halfing = 2
quot = 2 ** nb_halfing
reward = 50. / quot
from urllib2 import urlopen
from datetime import datetime, timedelta
bc=int(urlopen("http://blockexplorer.com/q/getblockcount").read())
iv=float(urlopen("http://blockexplorer.com/q/interval").read())
# smoothing
iv = (iv + 600) / 2.0
half = 210000 * nb_halfing
eta = (half - bc) * iv
utc_time = datetime.utcnow()
brh_local = datetime.now() + timedelta(seconds = eta)
brh_utc = utc_time + timedelta(seconds = eta)
print 'estim. for %.2f BTC/Block' % reward
print 'target block height: %s' % half
print 'current block height: %s' % bc
print 'remaining: %s' % (half - bc)
print 'current time (UTC) %s' % utc_time.isoformat()
print 'ETA (local): %s' % brh_local.isoformat()
print 'ETA (UTC): %s' % brh_utc.isoformat()
print 'time left: %s [s] = %.1f [min] = %.1f [h] = %.1f [d]' % (eta, eta/60, eta/60**2, eta/60**2/24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment