diff options
author | Gregory Sanders <gsanders87@gmail.com> | 2018-11-27 10:06:19 -0500 |
---|---|---|
committer | Gregory Sanders <gsanders87@gmail.com> | 2018-11-29 08:31:48 -0500 |
commit | 2012d4df23b7b065ccc1dbe596073d98e428fd3d (patch) | |
tree | 7f565e7c1bc56bff9e44f8fa6d3bc991a2fdc5f4 /test/functional/test_framework/script.py | |
parent | a4eaaa6ac53606a1533b56050af77961d8c27dc7 (diff) |
Add CScriptNum decode python implementation in functional suite
Diffstat (limited to 'test/functional/test_framework/script.py')
-rw-r--r-- | test/functional/test_framework/script.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py index 2fe44010ba..2c5ba24a6a 100644 --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -385,6 +385,22 @@ class CScriptNum: r[-1] |= 0x80 return bytes([len(r)]) + r + @staticmethod + def decode(vch): + result = 0 + # We assume valid push_size and minimal encoding + value = vch[1:] + if len(value) == 0: + return result + for i, byte in enumerate(value): + result |= int(byte) << 8*i + if value[-1] >= 0x80: + # Mask for all but the highest result bit + num_mask = (2**(len(value)*8) - 1) >> 1 + result &= num_mask + result *= -1 + return result + class CScript(bytes): """Serialized script |