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
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
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
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
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