mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Add CScriptNum decode python implementation in functional suite
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user