X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Futil.py;h=36e259d7198aa7dc80914f43b4f4c09259f047e3;hb=679245b565edcb2a03d865df3c08e86c0d6f402d;hp=3e88fd8be0c37948c11bd0cf384d358443197c09;hpb=1e086b3786e3708cb71205962d9db1684f2271f2;p=stratum-mining.git diff --git a/lib/util.py b/lib/util.py index 3e88fd8..36e259d 100644 --- a/lib/util.py +++ b/lib/util.py @@ -139,14 +139,14 @@ def b58decode(v, length): result = chr(0)*nPad + result if length is not None and len(result) != length: return None - + return result def reverse_hash(h): # This only revert byte order, nothing more if len(h) != 64: raise Exception('hash must have 64 hexa chars') - + return ''.join([ h[56-i:64-i] for i in range(0, 64, 8) ]) def doublesha(b): @@ -160,17 +160,17 @@ def address_to_pubkeyhash(addr): addr = b58decode(addr, 25) except: return None - + if addr is None: return None - + ver = addr[0] cksumA = addr[-4:] cksumB = doublesha(addr[:-4])[:4] - + if cksumA != cksumB: return None - + return (ver, addr[1:-4]) def ser_uint256_be(u): @@ -179,7 +179,7 @@ def ser_uint256_be(u): for i in xrange(8): rs += struct.pack(">I", u & 0xFFFFFFFFL) u >>= 32 - return rs + return rs def deser_uint256_be(f): r = 0L @@ -188,14 +188,19 @@ def deser_uint256_be(f): r += t << (i * 32) return r -def ser_number(num): +def ser_number(n): # For encoding nHeight into coinbase - d = struct.pack(" 127: + s[0] += 1 + s.append(n % 256) + n //= 256 + s.append(n) + return bytes(s) + def script_to_address(addr): d = address_to_pubkeyhash(addr) if not d: raise ValueError('invalid address') (ver, pubkeyhash) = d - return b'\x76\xa9\x14' + pubkeyhash + b'\x88\xac' \ No newline at end of file + return b'\x76\xa9\x14' + pubkeyhash + b'\x88\xac'