Add CScriptNum decode python implementation in functional suite

This commit is contained in:
Gregory Sanders 2018-11-27 10:06:19 -05:00
commit 2012d4df23
2 changed files with 26 additions and 2 deletions
test/functional/test_framework

View file

@ -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