def push_bytes(data): ms = StreamManager.get_stream() writer = BinaryWriter(ms) if len(data) == 0: raise ValueError("push data error: data is null") if len(data) <= int.from_bytes(PUSHBYTES75, 'little') + 1 - int.from_bytes( PUSHBYTES1, 'little'): num = len(data) + int.from_bytes(PUSHBYTES1, 'little') - 1 writer.write_byte(num) elif len(data) < 0x100: writer.write_byte(PUSHDATA1) writer.write_uint8(len(data)) elif len(data) < 0x10000: writer.write_byte(PUSHDATA2) writer.write_uint16(len(data)) else: writer.write_byte(PUSHDATA4) writer.write_uint32(len(data)) writer.write_bytes(data) ms.flush() res = ms.to_bytes() StreamManager.release_stream(ms) res = bytes_reader(res) return res
def serialize(self) -> bytes: invoke_script = ProgramBuilder.program_from_params(self.__sig_data) if len(self.public_keys) == 0: raise SDKException(ErrorCode.other_error('Public key in sig is empty.')) if len(self.public_keys) == 1: verification_script = ProgramBuilder.program_from_pubkey(self.public_keys[0]) else: verification_script = ProgramBuilder.program_from_multi_pubkey(self.m, self.public_keys) ms = StreamManager.get_stream() writer = BinaryWriter(ms) writer.write_var_bytes(invoke_script) writer.write_var_bytes(verification_script) ms.flush() res = ms.to_bytes() res = bytes_reader(res) StreamManager.release_stream(ms) return res