MCPcopy Create free account
hub / github.com/LUX-Core/lux / __coerce_instance

Method __coerce_instance

test/functional/test_framework/script.py:664–682  ·  view source on GitHub ↗
(cls, other)

Source from the content-addressed store, hash-verified

662 """
663 @classmethod
664 def __coerce_instance(cls, other):
665 # Coerce other into bytes
666 if isinstance(other, CScriptOp):
667 other = bchr(other)
668 elif isinstance(other, CScriptNum):
669 if (other.value == 0):
670 other = bchr(CScriptOp(OP_0))
671 else:
672 other = CScriptNum.encode(other)
673 elif isinstance(other, int):
674 if 0 <= other <= 16:
675 other = bytes(bchr(CScriptOp.encode_op_n(other)))
676 elif other == -1:
677 other = bytes(bchr(OP_1NEGATE))
678 else:
679 other = CScriptOp.encode_op_pushdata(bn2vch(other))
680 elif isinstance(other, (bytes, bytearray)):
681 other = CScriptOp.encode_op_pushdata(other)
682 return other
683
684 def __add__(self, other):
685 # Do the coercion outside of the try block so that errors in it are

Callers 2

__add__Method · 0.95
coerce_iterableMethod · 0.45

Calls 5

CScriptOpClass · 0.70
bn2vchFunction · 0.70
encodeMethod · 0.45
encode_op_nMethod · 0.45
encode_op_pushdataMethod · 0.45

Tested by

no test coverage detected