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

Method __coerce_instance

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

Source from the content-addressed store, hash-verified

439
440 @classmethod
441 def __coerce_instance(cls, other):
442 # Coerce other into bytes
443 if isinstance(other, CScriptOp):
444 other = bytes([other])
445 elif isinstance(other, CScriptNum):
446 if (other.value == 0):
447 other = bytes([CScriptOp(OP_0)])
448 else:
449 other = CScriptNum.encode(other)
450 elif isinstance(other, int):
451 if 0 <= other <= 16:
452 other = bytes([CScriptOp.encode_op_n(other)])
453 elif other == -1:
454 other = bytes([OP_1NEGATE])
455 else:
456 other = CScriptOp.encode_op_pushdata(bn2vch(other))
457 elif isinstance(other, (bytes, bytearray)):
458 other = CScriptOp.encode_op_pushdata(other)
459 return other
460
461 def __add__(self, other):
462 # add makes no sense for a CScript()

Callers 1

coerce_iterableMethod · 0.80

Calls 5

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

Tested by

no test coverage detected