def unserialize(data): len_parameter, data = Serialize.unserialize_variable_int(data) parameter = data[:len_parameter] len_code, data = Serialize.unserialize_variable_int( data[len_parameter:]) code = data[:len_code] program = Program(parameter=parameter.hex(), code=code.hex()) return program, data[len_code:]
def serialize(self): data_list = [] data_list.append( Serialize.serialize_bytes( encoding.hexstring_to_bytes(self.parameter, reverse=False))) data_list.append( Serialize.serialize_bytes( encoding.hexstring_to_bytes(self.code, reverse=False))) return b''.join(data_list)
def serialize(self): data_list = [] data_list.append(Serialize.serialize_bytes(self.name)) data_list.append(Serialize.serialize_bytes(self.description)) data_list.append(struct.pack("B", self.precision)) data_list.append(struct.pack("B", self.asset_type)) data_list.append(struct.pack("B", self.record_type)) data_list.append(struct.pack("<Q", self.value)) data_list.append(self.controller) return b''.join(data_list)
def serialize(self): data_list = [] data_list.append(self.serialize_unsigned()) data_list.append(Serialize.serialize_variable_int(len(self.programs))) for program in self.programs: data_list.append(program.serialize()) return b''.join(data_list)
def unserialize(data): usage = data[0] if not isValidAttribute(usage): raise ValueError('Attribute is invalid.') attribute_data, data = Serialize.unserialize_bytes(data[1:]) attribute = Attribute(usage=usage, data=attribute_data) return attribute, data
def unserialize(data: bytes): name, data = Serialize.unserialize_bytes(data) description, data = Serialize.unserialize_bytes(data) precision = data[0] # if precision <= b'0x00': if precision <= 0: raise ValueError('Precision is less than 0.') asset_type = data[1] # if asset_type <= b'0x00': if asset_type not in [0, 1]: raise ValueError('Asset type is less than 0.') record_type = data[2] value = struct.unpack("<Q", data[3:11])[0] controller = data[11:32] registerAssetPayload = PayloadRegisterAsset(name=name, description=description, precision=precision, asset_type=asset_type, record_type=record_type, value=value, controller=controller) return registerAssetPayload, data[32:]
def serialize_unsigned(self): data_list = [] data_list.append(struct.pack('B', self.tx_type)) data_list.append(struct.pack('B', self.payload_version)) data_list.append(self.payload.serialize()) data_list.append(Serialize.serialize_variable_int(len( self.attributes))) for attribute in self.attributes: data_list.append(attribute.serialize()) data_list.append(Serialize.serialize_variable_int(len(self.inputs))) for _input in self.inputs: data_list.append(_input.serialize()) data_list.append(Serialize.serialize_variable_int(len(self.outputs))) for output in self.outputs: data_list.append(output.serialize()) data_list.append(struct.pack("<L", self.lock_time)) return b''.join(data_list)
def unserialize(data): tx_type = data[0] payload_version = data[1] payload, data = p.Payload.unserialize(data[2:], tx_type, payload_version) count_attribute, data = Serialize.unserialize_variable_int(data) attributes = [] for i in range(count_attribute): attribute, data = Attribute.unserialize(data) attributes.append(attribute) num_inputs, data = Serialize.unserialize_variable_int(data) inputs = [] for i in range(num_inputs): tx_input, data = TxInput.unserialize(data) inputs.append(tx_input) outputs = [] num_outputs, data = Serialize.unserialize_variable_int(data) for i in range(num_outputs): tx_output, data = TxOutput.unserialize(data) outputs.append(tx_output) lock_time = struct.unpack("<L", data[:4])[0] count_program, data = Serialize.unserialize_variable_int(data[4:]) programs = [] for i in range(count_program): program, data = p.Program.unserialize(data) programs.append(program) tx = Transaction(tx_type=tx_type, payload_version=payload_version, payload=payload, attributes=attributes, inputs=inputs, outputs=outputs, lock_time=lock_time, programs=programs) return tx, data
def serialize_size(self): data_size = 0 data_size += 2 data_size += p.Payload.serialize_size(self.payload) count_attributes = len(self.attributes) data_size += Serialize.serialize_variable_int_size(count_attributes) for i in range(count_attributes): data_size += self.attributes[i].serialize_size() count_inputs = len(self.inputs) data_size += Serialize.serialize_variable_int_size( count_inputs) + count_inputs * TxInput.serialize_size() count_outputs = len(self.outputs) data_size += Serialize.serialize_variable_int_size( count_outputs) + count_outputs * TxOutput.serialize_size() data_size += 4 count_programs = len(self.programs) data_size += Serialize.serialize_variable_int_size(count_programs) for i in range(count_programs): data_size += self.programs[i].serialize_size() return data_size
def serialize_size(self): len_name = len(self.name) len_description = len(self.description) return Serialize.serialize_variable_int_size(len_name) + len_name + \ Serialize.serialize_variable_int_size(len_description) + len_description + 3 + 8 + 21
def unserialize(data): payload, data = Serialize.unserialize_bytes(data) coinbase_payload = PayloadCoinBase(payload=payload) return coinbase_payload, data
def serialize_size(self): len_payload = len(self.payload) return Serialize.serialize_variable_int_size(len_payload) + len_payload
def serialize(self): return Serialize.serialize_bytes(self.payload)
def serialize_size(self): len_parameter = len(self.parameter) len_code = len(self.code) return Serialize.serialize_variable_int_size(len_parameter) + len_parameter + \ Serialize.serialize_variable_int_size(len_code) + len_code
def serialize_size(self): len_data = len(self.data) return 1 + Serialize.serialize_variable_int_size(len_data) + len_data
def serialize(self): data_list = [] data_list.append(struct.pack('B', self.usage)) data_list.append(Serialize.serialize_bytes(self.data)) return b''.join(data_list)