MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / __coerce_instance

Method __coerce_instance

qa/rpc-tests/test_framework/script.py:652–670  ·  view source on GitHub ↗
(cls, other)

Source from the content-addressed store, hash-verified

650 """
651 @classmethod
652 def __coerce_instance(cls, other):
653 # Coerce other into bytes
654 if isinstance(other, CScriptOp):
655 other = bchr(other)
656 elif isinstance(other, CScriptNum):
657 if (other.value == 0):
658 other = bchr(CScriptOp(OP_0))
659 else:
660 other = CScriptNum.encode(other)
661 elif isinstance(other, (int, long)):
662 if 0 <= other <= 16:
663 other = bytes(bchr(CScriptOp.encode_op_n(other)))
664 elif other == -1:
665 other = bytes(bchr(OP_1NEGATE))
666 else:
667 other = CScriptOp.encode_op_pushdata(bn2vch(other))
668 elif isinstance(other, (bytes, bytearray)):
669 other = CScriptOp.encode_op_pushdata(other)
670 return other
671
672 def __add__(self, other):
673 # Do the coercion outside of the try block so that errors in it are

Callers 2

__add__Method · 0.95
coerce_iterableMethod · 0.80

Calls 5

bn2vchFunction · 0.90
CScriptOpClass · 0.85
encodeMethod · 0.80
encode_op_nMethod · 0.80
encode_op_pushdataMethod · 0.80

Tested by

no test coverage detected