def marshal(self): """Marshals the BalanceIncrease according to the byte-level representation shown at https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#balance-increase """ data = self.ec_public_key data += self.tx_id data += varint.encode(self.index) data += varint.encode(self.quantity) return data
def marshal(self): """ Marshal the object into its byte representation: - the first byte is a length descriptor varint (8 at the maximum) - next varint bytes is the descriptor height at which the output will not be created - next varint bytes is the index into the specified descriptor that will not be created :return: bytes representation of the CoinbaseDescriptorCancel message """ buf = bytearray() bodybuf = bytearray() bodybuf.extend(varint.encode(self.descriptor_height)) bodybuf.extend(varint.encode(self.descriptor_index)) buf.extend(varint.encode(len(bodybuf))) buf.extend(bodybuf) return bytes(buf)
def marshal(self) -> bytes: buf = bytearray() buf.extend(AdminBlockHeader.CHAIN_ID) buf.extend(self.prev_back_reference_hash) buf.extend(struct.pack(">I", self.height)) buf.extend(varint.encode(len(self.expansion_area))) buf.extend(self.expansion_area) buf.extend(struct.pack(">I", self.message_count)) buf.extend(struct.pack(">I", self.body_size)) return bytes(buf)
def marshal(self): """ Marshal the object into its byte representation: - the first byte is a length descriptor varint (10232 at the maximum) - next varint bytes is the descriptor height at which the output will not be created - next varint bytes is the index into the specified descriptor that will not be created The Coinbase Descriptor cannot be larger than 10233 bytes: (1 AdminID byte + 2 varint length bytes + (10 KiB max FCT tx - 10 header bytes of coinbase)) :return: bytes representation of the CoinbaseDescriptor message """ buf = bytearray() bodybuf = bytearray() for output in self.outputs: bodybuf.extend(varint.encode(output.get("value"))) bodybuf.extend(output.get("fct_address")) buf.extend(varint.encode(len(bodybuf))) buf.extend(bodybuf) return bytes(buf)
def marshal(self) -> bytes: buf = bytearray() buf.extend(EntryCreditBlockHeader.CHAIN_ID) buf.extend(self.body_hash) buf.extend(self.prev_header_hash) buf.extend(self.prev_full_hash) buf.extend(struct.pack(">I", self.height)) buf.extend(varint.encode(len(self.expansion_area))) buf.extend(self.expansion_area) buf.extend(struct.pack(">Q", self.object_count)) buf.extend(struct.pack(">Q", self.body_size)) return bytes(buf)
def marshal_for_signature(self): """Marshals the transaction's header and partial body, in order to be signed by a key""" buf = bytearray() buf.append(0x02) buf.extend(self.timestamp.to_bytes(6, "big", signed=False)) buf.append(len(self.inputs)) buf.append(len(self.outputs)) buf.append(len(self.ec_purchases)) for i in self.inputs: value = i.get("value") fct_address = i.get("fct_address") buf.extend(varint.encode(value) + fct_address) for o in self.outputs: value = o.get("value") fct_address = o.get("fct_address") buf.extend(varint.encode(value) + fct_address) for purchase in self.ec_purchases: value = purchase.get("value") ec_public_key = purchase.get("ec_public_key") buf.extend(varint.encode(value) + ec_public_key) return bytes(buf)
def marshal(self) -> bytes: buf = bytearray() buf.extend(FactoidBlockHeader.CHAIN_ID) buf.extend(self.body_mr) buf.extend(self.prev_keymr) buf.extend(self.prev_ledger_keymr) buf.extend(struct.pack(">Q", self.ec_exchange_rate)) buf.extend(struct.pack(">I", self.height)) buf.extend(varint.encode(len(self.expansion_area))) buf.extend(self.expansion_area) buf.extend(struct.pack(">I", self.tx_count)) buf.extend(struct.pack(">I", self.body_size)) return bytes(buf)
def marshal(self) -> bytes: """ Marshal the message into the following representation: - first byte is the message type (always 1) - next byte is the vm index - next 6 bytes are the timestamp - next 8 bytes are the salt - next 4 bytes are the salt number - next 32 bytes are the message hash being acknowledged - next 32 bytes are the full message hash - next 32 bytes are the leader chain id - next 4 bytes are the directory block height - next 4 bytes are the process list height TODO: is this actually the process list height? - next byte is the minute - next 32 bytes are the serial hash - next varint bytes are the data area size - next X bytes are the data area: - TODO: unmarshal the data area in Ack message - next 32 bytes are the public key - next 64 bytes are the signature :return: byte representation of the message """ buf = bytearray() buf.append(self.TYPE) buf.append(self.vm_index) buf.extend(self.timestamp) buf.extend(self.salt) buf.extend(struct.pack(">I", self.salt_number)) buf.extend(self.message_hash) buf.extend(self.full_message_hash) buf.extend(self.leader_chain_id) buf.extend(struct.pack(">I", self.height)) buf.extend(struct.pack(">I", self.process_list_height)) buf.append(self.minute) buf.extend(self.serial_hash) buf.extend(varint.encode(len(self.data_area))) buf.extend(self.data_area) buf.extend(self.signature.marshal()) return bytes(buf)
def test_encode(self): for value_int, expected_varint in TestVarInt.mapping.items(): observed_varint = varint.encode(value_int) assert observed_varint == expected_varint, "{}: 0x{} != 0x{}".format( value_int, observed_varint.hex(), expected_varint.hex())