File tree 1 file changed +20
-3
lines changed
test/functional/test_framework
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):
368
368
369
369
@staticmethod
370
370
def encode (obj ):
371
+ val = obj .value
371
372
r = bytearray (0 )
372
- if obj . value == 0 :
373
+ if val == 0 :
373
374
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
376
377
while (absvalue ):
377
378
r .append (absvalue & 0xff )
378
379
absvalue >>= 8
@@ -382,6 +383,22 @@ def encode(obj):
382
383
r [- 1 ] |= 0x80
383
384
return bytes ([len (r )]) + r
384
385
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
385
402
386
403
class CScript (bytes ):
387
404
"""Serialized script
You can’t perform that action at this time.
0 commit comments