Example #1
0
    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
Example #2
0
    def serialize(self):
        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 bytes_reader(temp)
    def serialize(self):
        invoke_script = ProgramBuilder.program_from_params(self.sig_data)
        if len(self.public_keys) == 0:
            raise ValueError("np public key in sig")

        verification_script = ProgramBuilder.program_from_pubkey(self.public_keys[0])
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)
        writer.WriteVarBytes(invoke_script)
        writer.WriteVarBytes(verification_script)
        ms.flush()
        res = ms.ToArray()
        res = bytes_reader(res)
        StreamManager.ReleaseStream(ms)
        return res
Example #4
0
def serialize_unsigned(tx):
    ms = StreamManager.GetStream()
    writer = BinaryWriter(ms)
    writer.WriteUInt8(tx.version)
    writer.WriteUInt8(tx.tx_type)
    writer.WriteUInt32(tx.nonce)
    writer.WriteUInt64(tx.gas_price)
    writer.WriteUInt64(tx.gas_limit)
    writer.WriteBytes(tx.payer)
    writer.WriteBytes(tx.payload)
    writer.WriteVarInt(tx.attributes)
    ms.flush()
    res = ms.ToArray()
    StreamManager.ReleaseStream(ms)
    return res
Example #5
0
 def serialize_unsigned(self):
     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.encode()))
     writer.WriteBytes(bytes(self.payload))
     writer.WriteVarInt(len(self.attributes))
     ms.flush()
     res = ms.ToArray()
     StreamManager.ReleaseStream(ms)
     return res
    def serialize(self):
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)
        writer.WriteBytes(self.serialize_unsigned())
        writer.WriteVarInt(len(self.sigs))

        #temp = bytes_reader(temp)
        #tx_serial += temp
        for sig in self.sigs:
            #print(sig.M)
            #print(sig.public_keys)
            #print(sig.sig_data)
            writer.WriteBytes(sig.serialize())
            #tx_serial += serial_sig

        ms.flush()
        temp = ms.ToArray()
        StreamManager.ReleaseStream(ms)
        return bytes_reader(temp)