示例#1
0
 def __coerce_instance(cls, other):
     # Coerce other into bytes
     if isinstance(other, CScriptOp):
         other = bytes([other])
     elif isinstance(other, CScriptNum):
         if (other.value == 0):
             other = bytes([CScriptOp(OP_0)])
         else:
             other = CScriptNum.encode(other)
     elif isinstance(other, int):
         if 0 <= other <= 16:
             other = bytes([CScriptOp.encode_op_n(other)])
         elif other == -1:
             other = bytes([OP_1NEGATE])
         else:
             other = CScriptOp.encode_op_pushdata(bn2vch(other))
     elif isinstance(other, (bytes, bytearray)):
         other = bytes(CScriptOp.encode_op_pushdata(other))
     return other
示例#2
0
 def __coerce_instance(cls, other):
     # Coerce other into bytes
     if isinstance(other, CScriptOp):
         other = bchr(other)
     elif isinstance(other, CScriptNum):
         if (other.value == 0):
             other = bchr(CScriptOp(OP_0))
         else:
             other = CScriptNum.encode(other)
     elif isinstance(other, (int, long)):
         if 0 <= other <= 16:
             other = bytes(bchr(CScriptOp.encode_op_n(other)))
         elif other == -1:
             other = bytes(bchr(OP_1NEGATE))
         else:
             other = CScriptOp.encode_op_pushdata(bignum.bn2vch(other))
     elif isinstance(other, (bytes, bytearray)):
         other = CScriptOp.encode_op_pushdata(other)
     return other
 def __coerce_instance(cls, other):
     # coerce other into bytes
     if isinstance(other, cscriptop):
         other = bchr(other)
     elif isinstance(other, cscriptnum):
         if (other.value == 0):
             other = bchr(cscriptop(op_0))
         else:
             other = cscriptnum.encode(other)
     elif isinstance(other, (int, long)):
         if 0 <= other <= 16:
             other = bytes(bchr(cscriptop.encode_op_n(other)))
         elif other == -1:
             other = bytes(bchr(op_1negate))
         else:
             other = cscriptop.encode_op_pushdata(bignum.bn2vch(other))
     elif isinstance(other, (bytes, bytearray)):
         other = cscriptop.encode_op_pushdata(other)
     return other