Add CScriptNum decode python implementation in functional suite
This commit is contained in:
parent
a4eaaa6ac5
commit
2012d4df23
2 changed files with 26 additions and 2 deletions
test/functional/test_framework
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue