1717from __future__ import absolute_import , division , print_function , unicode_literals
1818
1919import sys
20- bchr = chr
21- bord = ord
20+ _bchr = chr
21+ _bord = ord
2222if sys .version > '3' :
2323 long = int
24- bchr = lambda x : bytes ([x ])
25- bord = lambda x : x
24+ _bchr = lambda x : bytes ([x ])
25+ _bord = lambda x : x
2626
2727import copy
2828import struct
@@ -47,9 +47,9 @@ class CScriptOp(int):
4747 def encode_op_pushdata (d ):
4848 """Encode a PUSHDATA op, returning bytes"""
4949 if len (d ) < 0x4c :
50- return b'' + bchr (len (d )) + d # OP_PUSHDATA
50+ return b'' + _bchr (len (d )) + d # OP_PUSHDATA
5151 elif len (d ) <= 0xff :
52- return b'\x4c ' + bchr (len (d )) + d # OP_PUSHDATA1
52+ return b'\x4c ' + _bchr (len (d )) + d # OP_PUSHDATA1
5353 elif len (d ) <= 0xffff :
5454 return b'\x4d ' + struct .pack (b'<H' , len (d )) + d # OP_PUSHDATA2
5555 elif len (d ) <= 0xffffffff :
@@ -520,12 +520,12 @@ class CScript(bytes):
520520 def __coerce_instance (cls , other ):
521521 # Coerce other into bytes
522522 if isinstance (other , CScriptOp ):
523- other = bchr (other )
523+ other = _bchr (other )
524524 elif isinstance (other , (int , long )):
525525 if 0 <= other <= 16 :
526- other = bytes (bchr (CScriptOp .encode_op_n (other )))
526+ other = bytes (_bchr (CScriptOp .encode_op_n (other )))
527527 elif other == - 1 :
528- other = bytes (bchr (OP_1NEGATE ))
528+ other = bytes (_bchr (OP_1NEGATE ))
529529 else :
530530 other = CScriptOp .encode_op_pushdata (bitcoin .core .bignum .bn2vch (
531531 other ))
@@ -572,7 +572,7 @@ def raw_iter(self):
572572 i = 0
573573 while i < len (self ):
574574 sop_idx = i
575- opcode = bord (self [i ])
575+ opcode = _bord (self [i ])
576576 i += 1
577577
578578 if opcode > OP_PUSHDATA4 :
@@ -589,24 +589,24 @@ def raw_iter(self):
589589 if i >= len (self ):
590590 raise CScriptInvalidError (
591591 'PUSHDATA1: missing data length' )
592- datasize = bord (self [i ])
592+ datasize = _bord (self [i ])
593593 i += 1
594594
595595 elif opcode == OP_PUSHDATA2 :
596596 pushdata_type = 'PUSHDATA2'
597597 if i + 1 >= len (self ):
598598 raise CScriptInvalidError (
599599 'PUSHDATA2: missing data length' )
600- datasize = bord (self [i ]) + (bord (self [i + 1 ]) << 8 )
600+ datasize = _bord (self [i ]) + (_bord (self [i + 1 ]) << 8 )
601601 i += 2
602602
603603 elif opcode == OP_PUSHDATA4 :
604604 pushdata_type = 'PUSHDATA4'
605605 if i + 3 >= len (self ):
606606 raise CScriptInvalidError (
607607 'PUSHDATA4: missing data length' )
608- datasize = bord (self [i ]) + (bord (self [i + 1 ]) << 8 ) + (
609- bord (self [i + 2 ]) << 16 ) + (bord (self [i + 3 ]) << 24 )
608+ datasize = _bord (self [i ]) + (_bord (self [i + 1 ]) << 8 ) + (
609+ _bord (self [i + 2 ]) << 16 ) + (_bord (self [i + 3 ]) << 24 )
610610 i += 4
611611
612612 else :
@@ -677,8 +677,8 @@ def is_p2sh(self):
677677
678678 Note that this test is consensus-critical.
679679 """
680- return (len (self ) == 23 and bord (self [0 ]) == OP_HASH160 and
681- bord (self [1 ]) == 0x14 and bord (self [22 ]) == OP_EQUAL )
680+ return (len (self ) == 23 and _bord (self [0 ]) == OP_HASH160 and
681+ _bord (self [1 ]) == 0x14 and _bord (self [22 ]) == OP_EQUAL )
682682
683683 def is_push_only (self ):
684684 """Test if the script only contains pushdata ops
@@ -709,7 +709,7 @@ def has_canonical_pushes(self):
709709 continue
710710
711711 elif op < OP_PUSHDATA1 and op > OP_0 and len (
712- data ) == 1 and bord (data [0 ]) <= 16 :
712+ data ) == 1 and _bord (data [0 ]) <= 16 :
713713 # Could have used an OP_n code, rather than a 1-byte push.
714714 return False
715715
@@ -731,7 +731,7 @@ def has_canonical_pushes(self):
731731
732732 def is_unspendable (self ):
733733 """Test if the script is provably unspendable"""
734- return (len (self ) > 0 and bord (self [0 ]) == OP_RETURN )
734+ return (len (self ) > 0 and _bord (self [0 ]) == OP_RETURN )
735735
736736 def is_valid (self ):
737737 """Return True if the script is valid, False otherwise
0 commit comments