diff --git a/p2pool/data.py b/p2pool/data.py index e8fe347cc..40281e94b 100644 --- a/p2pool/data.py +++ b/p2pool/data.py @@ -12,6 +12,28 @@ from p2pool.bitcoin import data as bitcoin_data, script, sha256 from p2pool.util import math, forest, pack +def deserialize_bignum(str_, len_): + result = 0L + for idx in xrange(len_//8): + limb, str_ = pack.IntType(64).unpack(str_[:8]), str_[8:] + result += limb << (idx * 64) + if len_ & 4: + limb, str_ = pack.IntType(32).unpack(str_[:4]), str_[4:] + result += limb << ((len_ & ~7) * 8) + if len_ & 2: + limb, str_ = pack.IntType(16).unpack(str_[:2]), str_[2:] + result += limb << ((len_ & ~3) * 8) + if len_ & 1: + limb, str_ = pack.IntType(8).unpack(str_[:1]), str_[1:] + result += limb << ((len_ & ~1) * 8) + return result +def parse_bip0034(coinbase): + _, opdata = script.parse(coinbase).next() + bignum = deserialize_bignum(opdata, len(opdata)) + if ord(opdata[-1]) & 0x80: + bignum = -bignum + return (bignum,) + # hashlink hash_link_type = pack.ComposedType([ diff --git a/p2pool/web.py b/p2pool/web.py index 7a6eff8f6..381cfd8e6 100644 --- a/p2pool/web.py +++ b/p2pool/web.py @@ -218,7 +218,7 @@ def decent_height(): web_root.putChild('recent_blocks', WebInterface(lambda: [dict( ts=s.timestamp, hash='%064x' % s.header_hash, - number=pack.IntType(24).unpack(s.share_data['coinbase'][1:4]) if len(s.share_data['coinbase']) >= 4 else None, + number=p2pool_data.parse_bip0034(s.share_data['coinbase'])[0], share='%064x' % s.hash, ) for s in node.tracker.get_chain(node.best_share_var.value, min(node.tracker.get_height(node.best_share_var.value), 24*60*60//node.net.SHARE_PERIOD)) if s.pow_hash <= s.header['bits'].target])) web_root.putChild('uptime', WebInterface(lambda: time.time() - start_time))