コード例 #1
0
    def serialize(self, r: bytes, version: int):
        if len(self.cross_chain_addresses) != len(self.output_indexes) or \
                len(self.cross_chain_addresses) != len(self.cross_chain_addresses):
            Logger.error("Invalid cross chain asset")
            return None

        r += serialize.write_var_uint(len(self.cross_chain_addresses))

        for i in range(len(self.cross_chain_addresses)):
            r = serialize.write_var_bytes(r, bytes(self.cross_chain_addresses[i].encode()))
            r += serialize.write_var_uint(self.output_indexes[i])
            r += struct.pack("<q", self.cross_chain_amounts[i])

        return r
コード例 #2
0
    def serialize(self):
        r = self.serialize_unsigned()
        r += serialize.write_var_uint(len(self.programs))

        for program in self.programs:
            r += program.serialize()

        return r
コード例 #3
0
 def serialize_unsigned(self, r: bytes, version=0):
     r += self.proposal_hash
     r += self.document_hash
     r += serialize.write_var_uint(self.stage)
     r = serialize.write_var_bytes(r, self.leader_public_key)
     if self.new_leader_public_key is not None:
         r = serialize.write_var_bytes(r, self.new_leader_public_key)
     else:
         r += struct.pack("<B", CRCProposalTracking.DEFAULT)
     return r
コード例 #4
0
 def serialize_unsigned_normal_or_elip(self, r: bytes, version=0):
     r += struct.pack("<H", self.proposal_type)
     r = serialize.write_var_bytes(r, bytes(self.category_data.encode()))
     r = serialize.write_var_bytes(r, bytes.fromhex(self.account.public_key()))
     r += self.draft_hash
     r += serialize.write_var_uint(len(self.budget))
     for budget in self.budget:
         r += budget.serialize(version)
     r += self.recipient
     return r
コード例 #5
0
    def serialize_unsigned(self):
        # version
        r = b""
        if self.version >= self.TX_VERSION_09:
            r += struct.pack(">B", self.version)

        # tx type
        r += struct.pack(">B", self.tx_type)

        # payload version
        r += struct.pack(">B", self.payload_version)

        # payload
        if self.payload is None:
            Logger.error("Transaction payload is None")
            return None

        if self.payload.data(self.payload_version) is not None:
            r += self.payload.data(self.payload_version)

        # attributes
        if self.attributes is not None:
            r += serialize.write_var_uint(len(self.attributes))
            for attribute in self.attributes:
                r += attribute.serialize()

        # inputs
        if self.inputs is not None:
            r += serialize.write_var_uint(len(self.inputs))
            for input in self.inputs:
                r += input.serialize()

        # outputs
        if self.outputs is not None:
            r += serialize.write_var_uint(len(self.outputs))
            for output in self.outputs:
                r += output.serialize(self.version)

        # lock_time
        r += struct.pack("<I", self.lock_time)

        return r
コード例 #6
0
    def serialize(self, version: int):
        if self.candidates is None or len(self.candidates) == 0:
            Logger.error("candidates list is empty!")
            return None
        r = b""
        r += struct.pack("<B", self.vote_type)
        r += serialize.write_var_uint(len(self.candidates))
        for candidate in self.candidates:
            r = serialize.write_var_bytes(r, candidate)

        return r
コード例 #7
0
    def serialize(self):
        if self.contents is None or len(self.contents) == 0:
            Logger.error("contents is invalid")
            return None

        r = b""
        r += struct.pack("<B", self.version)
        r += serialize.write_var_uint(len(self.contents))
        for content in self.contents:
            r += content.serialize(self.version)

        return r
コード例 #8
0
    def serialize(self):

        if self.serialize_data is not None:
            return self.serialize_data

        r = self.serialize_unsigned()
        r += serialize.write_var_uint(len(self.programs))

        for program in self.programs:
            r += program.serialize()

        self.serialize_data = r
        return r