File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -368,11 +368,12 @@ def __init__(self, d=0):
368368
369369 @staticmethod
370370 def encode (obj ):
371+ val = obj .value
371372 r = bytearray (0 )
372- if obj . value == 0 :
373+ if val == 0 :
373374 return bytes (r )
374- neg = obj . value < 0
375- absvalue = - obj . value if neg else obj . value
375+ neg = val < 0
376+ absvalue = - val if neg else val
376377 while (absvalue ):
377378 r .append (absvalue & 0xff )
378379 absvalue >>= 8
@@ -382,6 +383,22 @@ def encode(obj):
382383 r [- 1 ] |= 0x80
383384 return bytes ([len (r )]) + r
384385
386+ @staticmethod
387+ def decode (vch ):
388+ # We assume valid push_size and minimal encoding
389+ value = vch [1 :]
390+ # Mask for all but the highest result bit
391+ num_mask = (2 ** (len (value )* 8 ) - 1 ) >> 1
392+ if len (value ) == 0 :
393+ return 0
394+ else :
395+ result = 0
396+ for i in range (len (value )):
397+ result |= int (value [i ]) << 8 * i
398+ if value [- 1 ] >= 0x80 :
399+ result &= num_mask
400+ result *= - 1
401+ return result
385402
386403class CScript (bytes ):
387404 """Serialized script
You can’t perform that action at this time.
0 commit comments