def serialize(self) -> bytes:
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)
        writer.WriteBytes(self.serialize_unsigned())
        writer.WriteVarInt(len(self.sigs))

        for sig in self.sigs:
            writer.WriteBytes(sig.serialize())

        ms.flush()
        temp = ms.ToArray()
        StreamManager.ReleaseStream(ms)
        return a2b_hex(temp)
 def push_bytes(data):
     ms = StreamManager.GetStream()
     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.WriteByte(num)
     elif len(data) < 0x100:
         writer.WriteByte(PUSHDATA1)
         writer.WriteUInt8(len(data))
     elif len(data) < 0x10000:
         writer.WriteByte(PUSHDATA2)
         writer.WriteUInt16(len(data))
     else:
         writer.WriteByte(PUSHDATA4)
         writer.WriteUInt32(len(data))
     writer.WriteBytes(data)
     ms.flush()
     res = ms.ToArray()
     StreamManager.ReleaseStream(ms)
     res = bytes_reader(res)
     return res
 def serialize_unsigned(self) -> bytes:
     ms = StreamManager.GetStream()
     writer = BinaryWriter(ms)
     writer.WriteUInt8(self.version)
     writer.WriteUInt8(self.tx_type)
     writer.WriteUInt32(self.nonce)
     writer.WriteUInt64(self.gas_price)
     writer.WriteUInt64(self.gas_limit)
     writer.WriteBytes(bytes(self.payer))
     writer.WriteVarBytes(bytes(self.payload))
     writer.WriteVarInt(len(self.attributes))
     ms.flush()
     res = ms.ToArray()
     StreamManager.ReleaseStream(ms)
     return res