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):
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):
for i in xrange(8):
rs += struct.pack(">I", u & 0xFFFFFFFFL)
u >>= 32
- return rs
+ return rs
def deser_uint256_be(f):
r = 0L
r += t << (i * 32)
return r
-def ser_number(num):
+def ser_number(n):
# For encoding nHeight into coinbase
- d = struct.pack("<I", num).rstrip("\x00")
- return chr(len(d)) + d
-
+ s = bytearray(b'\1')
+ while n > 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'