TransactionMetadata
- class cometa.auxiliary_data.transaction_metadata.TransactionMetadata(ptr=None)[source]
Bases:
objectRepresents transaction metadata as a map of labels to metadatum values.
Transaction metadata in Cardano is organized as a map where keys are unsigned 64-bit integers (labels) and values are Metadatum objects. Common labels include 721 for NFT metadata (CIP-25).
Example
>>> metadata = TransactionMetadata() >>> metadata.insert(721, Metadatum.from_string("NFT metadata"))
- classmethod from_cbor(reader)[source]
Deserializes TransactionMetadata from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the metadata data.
- Returns:
A new TransactionMetadata deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- insert(label, value)[source]
Inserts or updates a metadatum entry with the given label.
- Parameters:
label (int) – The metadata label (unsigned 64-bit integer).
value (Metadatum) – The metadatum value to associate with the label.
- Raises:
CardanoError – If insertion fails.
- Return type:
None
Example
>>> metadata.insert(721, nft_metadatum)
- get(label)[source]
Retrieves the metadatum associated with a label.
- Parameters:
label (int) – The metadata label to look up.
- Returns:
The Metadatum associated with the label.
- Raises:
CardanoError – If the label is not found or retrieval fails.
- Return type:
Example
>>> nft_meta = metadata.get(721)
- get_key_at(index)[source]
Retrieves the label at a specific index.
- Parameters:
index (int) – The index of the label to retrieve.
- Returns:
The label at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
int
- get_value_at(index)[source]
Retrieves the metadatum at a specific index.
- Parameters:
index (int) – The index of the metadatum to retrieve.
- Returns:
The Metadatum at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- get_key_value_at(index)[source]
Retrieves the key-value pair at a specific index.
- Parameters:
index (int) – The index of the key-value pair to retrieve.
- Returns:
A tuple containing the label (int) and Metadatum at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
tuple[int, Metadatum]
- get_keys()[source]
Retrieves all keys (labels) from the metadata.
- Returns:
A MetadatumLabelList containing all labels in the metadata.
- Raises:
CardanoError – If retrieval fails.
- Return type:
- to_cbor(writer)[source]
Serializes the transaction metadata to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
- __iter__()[source]
Iterates over all (label, metadatum) pairs.
- Return type:
Iterator[Tuple[int, Metadatum]]
- __contains__(label)[source]
Checks if a label exists in the metadata.
- Parameters:
label (int)
- Return type:
bool
- __getitem__(label)[source]
Gets a metadatum by label using bracket notation.
- Parameters:
label (int)
- Return type:
- __setitem__(label, value)[source]
Sets a metadatum by label using bracket notation.
- Parameters:
label (int)
value (Metadatum)
- Return type:
None
- to_cip116_json(writer)[source]
Serializes this object to CIP-116 compliant JSON.
- Parameters:
writer (JsonWriter) – The JsonWriter to write the JSON to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None