Skip to content

Commit

Permalink
simplified big0034 redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestv committed Jun 19, 2015
1 parent 0bc89a2 commit 2acfd3c
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions p2pool/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,9 @@
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))
bignum = pack.IntType(len(opdata)*8).unpack(opdata)
if ord(opdata[-1]) & 0x80:
bignum = -bignum
return (bignum,)
Expand Down

0 comments on commit 2acfd3c

Please sign in to comment.