10
10
from .mininode import CTransaction , CTxOut , sha256 , hash256 , uint256_from_str , ser_uint256 , ser_string
11
11
from binascii import hexlify
12
12
import hashlib
13
-
14
- import sys
15
- bchr = chr
16
- bord = ord
17
- if sys .version > '3' :
18
- long = int
19
- bchr = lambda x : bytes ([x ])
20
- bord = lambda x : x
21
-
22
13
import struct
23
14
24
15
from .bignum import bn2vch
@@ -40,9 +31,9 @@ class CScriptOp(int):
40
31
def encode_op_pushdata (d ):
41
32
"""Encode a PUSHDATA op, returning bytes"""
42
33
if len (d ) < 0x4c :
43
- return b'' + bchr ( len (d )) + d # OP_PUSHDATA
34
+ return b'' + bytes ([ len (d )] ) + d # OP_PUSHDATA
44
35
elif len (d ) <= 0xff :
45
- return b'\x4c ' + bchr ( len (d )) + d # OP_PUSHDATA1
36
+ return b'\x4c ' + bytes ([ len (d )] ) + d # OP_PUSHDATA1
46
37
elif len (d ) <= 0xffff :
47
38
return b'\x4d ' + struct .pack (b'<H' , len (d )) + d # OP_PUSHDATA2
48
39
elif len (d ) <= 0xffffffff :
@@ -388,7 +379,7 @@ def encode(obj):
388
379
r .append (0x80 if neg else 0 )
389
380
elif neg :
390
381
r [- 1 ] |= 0x80
391
- return bytes (bchr ( len (r )) + r )
382
+ return bytes (bytes ([ len (r )] ) + r )
392
383
393
384
394
385
class CScript (bytes ):
@@ -405,17 +396,17 @@ class CScript(bytes):
405
396
def __coerce_instance (cls , other ):
406
397
# Coerce other into bytes
407
398
if isinstance (other , CScriptOp ):
408
- other = bchr ( other )
399
+ other = bytes ([ other ] )
409
400
elif isinstance (other , CScriptNum ):
410
401
if (other .value == 0 ):
411
- other = bchr ( CScriptOp (OP_0 ))
402
+ other = bytes ([ CScriptOp (OP_0 )] )
412
403
else :
413
404
other = CScriptNum .encode (other )
414
405
elif isinstance (other , int ):
415
406
if 0 <= other <= 16 :
416
- other = bytes (bchr ( CScriptOp .encode_op_n (other )))
407
+ other = bytes (bytes ([ CScriptOp .encode_op_n (other )] ))
417
408
elif other == - 1 :
418
- other = bytes (bchr ( OP_1NEGATE ))
409
+ other = bytes (bytes ([ OP_1NEGATE ] ))
419
410
else :
420
411
other = CScriptOp .encode_op_pushdata (bn2vch (other ))
421
412
elif isinstance (other , (bytes , bytearray )):
@@ -458,7 +449,7 @@ def raw_iter(self):
458
449
i = 0
459
450
while i < len (self ):
460
451
sop_idx = i
461
- opcode = bord ( self [i ])
452
+ opcode = self [i ]
462
453
i += 1
463
454
464
455
if opcode > OP_PUSHDATA4 :
@@ -474,21 +465,21 @@ def raw_iter(self):
474
465
pushdata_type = 'PUSHDATA1'
475
466
if i >= len (self ):
476
467
raise CScriptInvalidError ('PUSHDATA1: missing data length' )
477
- datasize = bord ( self [i ])
468
+ datasize = self [i ]
478
469
i += 1
479
470
480
471
elif opcode == OP_PUSHDATA2 :
481
472
pushdata_type = 'PUSHDATA2'
482
473
if i + 1 >= len (self ):
483
474
raise CScriptInvalidError ('PUSHDATA2: missing data length' )
484
- datasize = bord ( self [i ]) + (bord ( self [i + 1 ]) << 8 )
475
+ datasize = self [i ] + (self [i + 1 ] << 8 )
485
476
i += 2
486
477
487
478
elif opcode == OP_PUSHDATA4 :
488
479
pushdata_type = 'PUSHDATA4'
489
480
if i + 3 >= len (self ):
490
481
raise CScriptInvalidError ('PUSHDATA4: missing data length' )
491
- datasize = bord ( self [i ]) + (bord ( self [i + 1 ]) << 8 ) + (bord ( self [i + 2 ]) << 16 ) + (bord ( self [i + 3 ]) << 24 )
482
+ datasize = self [i ] + (self [i + 1 ] << 8 ) + (self [i + 2 ] << 16 ) + (self [i + 3 ] << 24 )
492
483
i += 4
493
484
494
485
else :
0 commit comments