From 96e8e7e2937ea62757627350c3ea83f5bbae9772 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 28 Jan 2013 21:05:57 +0000 Subject: [PATCH] Bugfix: Serialized numbers are signed, so need an extra \x00 in the case of 0x80...-0xff... Function body taken from Eloipool's bitcoin/script.py encodeUNum function (does not work for zero or negative numbers) --- lib/util.py | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/util.py b/lib/util.py index 3e88fd8..45da424 100644 --- a/lib/util.py +++ b/lib/util.py @@ -188,11 +188,16 @@ 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: -- 1.7.1