1818from __future__ import absolute_import , division , print_function , unicode_literals
1919
2020import sys
21- bchr = chr
22- bord = ord
21+ _bchr = chr
22+ _bord = ord
2323if sys .version > '3' :
2424 long = int
25- bchr = lambda x : bytes ([x ])
26- bord = lambda x : x
25+ _bchr = lambda x : bytes ([x ])
26+ _bord = lambda x : x
2727
2828import copy
2929import struct
@@ -46,9 +46,9 @@ class CScriptOp(int):
4646 def encode_op_pushdata (d ):
4747 """Encode a PUSHDATA op, returning bytes"""
4848 if len (d ) < 0x4c :
49- return b'' + bchr (len (d )) + d # OP_PUSHDATA
49+ return b'' + _bchr (len (d )) + d # OP_PUSHDATA
5050 elif len (d ) <= 0xff :
51- return b'\x4c ' + bchr (len (d )) + d # OP_PUSHDATA1
51+ return b'\x4c ' + _bchr (len (d )) + d # OP_PUSHDATA1
5252 elif len (d ) <= 0xffff :
5353 return b'\x4d ' + struct .pack (b'<H' , len (d )) + d # OP_PUSHDATA2
5454 elif len (d ) <= 0xffffffff :
@@ -514,12 +514,12 @@ class CScript(bytes):
514514 def __coerce_instance (cls , other ):
515515 # Coerce other into bytes
516516 if isinstance (other , CScriptOp ):
517- other = bchr (other )
517+ other = _bchr (other )
518518 elif isinstance (other , (int , long )):
519519 if 0 <= other <= 16 :
520- other = bytes (bchr (CScriptOp .encode_op_n (other )))
520+ other = bytes (_bchr (CScriptOp .encode_op_n (other )))
521521 elif other == - 1 :
522- other = bytes (bchr (OP_1NEGATE ))
522+ other = bytes (_bchr (OP_1NEGATE ))
523523 else :
524524 other = CScriptOp .encode_op_pushdata (bitcoin .core .bignum .bn2vch (other ))
525525 elif isinstance (other , (bytes , bytearray )):
@@ -562,7 +562,7 @@ def raw_iter(self):
562562 i = 0
563563 while i < len (self ):
564564 sop_idx = i
565- opcode = bord (self [i ])
565+ opcode = _bord (self [i ])
566566 i += 1
567567
568568 if opcode > OP_PUSHDATA4 :
@@ -578,21 +578,21 @@ def raw_iter(self):
578578 pushdata_type = 'PUSHDATA1'
579579 if i >= len (self ):
580580 raise CScriptInvalidError ('PUSHDATA1: missing data length' )
581- datasize = bord (self [i ])
581+ datasize = _bord (self [i ])
582582 i += 1
583583
584584 elif opcode == OP_PUSHDATA2 :
585585 pushdata_type = 'PUSHDATA2'
586586 if i + 1 >= len (self ):
587587 raise CScriptInvalidError ('PUSHDATA2: missing data length' )
588- datasize = bord (self [i ]) + (bord (self [i + 1 ]) << 8 )
588+ datasize = _bord (self [i ]) + (_bord (self [i + 1 ]) << 8 )
589589 i += 2
590590
591591 elif opcode == OP_PUSHDATA4 :
592592 pushdata_type = 'PUSHDATA4'
593593 if i + 3 >= len (self ):
594594 raise CScriptInvalidError ('PUSHDATA4: missing data length' )
595- datasize = bord (self [i ]) + (bord (self [i + 1 ]) << 8 ) + (bord (self [i + 2 ]) << 16 ) + (bord (self [i + 3 ]) << 24 )
595+ datasize = _bord (self [i ]) + (_bord (self [i + 1 ]) << 8 ) + (_bord (self [i + 2 ]) << 16 ) + (_bord (self [i + 3 ]) << 24 )
596596 i += 4
597597
598598 else :
@@ -664,9 +664,9 @@ def is_p2sh(self):
664664 Note that this test is consensus-critical.
665665 """
666666 return (len (self ) == 23 and
667- bord (self [0 ]) == OP_HASH160 and
668- bord (self [1 ]) == 0x14 and
669- bord (self [22 ]) == OP_EQUAL )
667+ _bord (self [0 ]) == OP_HASH160 and
668+ _bord (self [1 ]) == 0x14 and
669+ _bord (self [22 ]) == OP_EQUAL )
670670
671671 def is_push_only (self ):
672672 """Test if the script only contains pushdata ops
@@ -696,7 +696,7 @@ def has_canonical_pushes(self):
696696 if op > OP_16 :
697697 continue
698698
699- elif op < OP_PUSHDATA1 and op > OP_0 and len (data ) == 1 and bord (data [0 ]) <= 16 :
699+ elif op < OP_PUSHDATA1 and op > OP_0 and len (data ) == 1 and _bord (data [0 ]) <= 16 :
700700 # Could have used an OP_n code, rather than a 1-byte push.
701701 return False
702702
@@ -719,7 +719,7 @@ def has_canonical_pushes(self):
719719 def is_unspendable (self ):
720720 """Test if the script is provably unspendable"""
721721 return (len (self ) > 0 and
722- bord (self [0 ]) == OP_RETURN )
722+ _bord (self [0 ]) == OP_RETURN )
723723
724724 def is_valid (self ):
725725 """Return True if the script is valid, False otherwise
0 commit comments