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

Method __coerce_instance

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

Source from the content-addressed store, hash-verified

395 """
396 @classmethod
397 def __coerce_instance(cls, other):
398 # Coerce other into bytes
399 if isinstance(other, CScriptOp):
400 other = bytes([other])
401 elif isinstance(other, CScriptNum):
402 if (other.value == 0):
403 other = bytes([CScriptOp(OP_0)])
404 else:
405 other = CScriptNum.encode(other)
406 elif isinstance(other, int):
407 if 0 <= other <= 16:
408 other = bytes([CScriptOp.encode_op_n(other)])
409 elif other == -1:
410 other = bytes([OP_1NEGATE])
411 else:
412 other = CScriptOp.encode_op_pushdata(bn2vch(other))
413 elif isinstance(other, (bytes, bytearray)):
414 other = CScriptOp.encode_op_pushdata(other)
415 return other
416
417 def __add__(self, other):
418 # 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

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

Tested by

no test coverage detected