MetadatumMap
- class cometa.auxiliary_data.metadatum_map.MetadatumMap(ptr=None)[source]
Bases:
Mapping[Metadatum, Metadatum]Represents a map of metadatum keys to metadatum values.
Both keys and values can be any valid metadatum type. Accepts Python primitives (int, str, bytes) directly for keys and values.
Example
>>> meta_map = MetadatumMap() >>> meta_map["name"] = "Alice" # str key and value >>> meta_map["age"] = 30 # str key, int value >>> meta_map[1] = b"\xde\xad" # int key, bytes value >>> len(meta_map) 3 >>> "name" in meta_map True
- __init__(ptr=None)[source]
Initializes a new MetadatumMap.
- Parameters:
ptr – Optional FFI pointer to an existing map. If None, creates a new empty map.
- Raises:
CardanoError – If map creation fails or if ptr is NULL.
- Return type:
None
- __exit__(exc_type, exc_val, exc_tb)[source]
Cleans up when exiting context manager.
- Return type:
None
- classmethod from_cbor(reader)[source]
Deserializes a MetadatumMap from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the map data.
- Returns:
A new MetadatumMap deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- insert(key, value)[source]
Inserts or updates a key-value pair.
- Parameters:
- Raises:
CardanoError – If insertion fails.
TypeError – If key or value cannot be converted to Metadatum.
- Return type:
None
Example
>>> meta_map = MetadatumMap() >>> meta_map.insert("name", "Alice") >>> meta_map.insert(1, 42)
- get(key, default=None)[source]
Retrieves the value for a given key.
- Parameters:
- Returns:
The Metadatum value associated with the key, or default if not found.
- Raises:
TypeError – If key cannot be converted to Metadatum.
- Return type:
Metadatum | None
- to_cbor(writer)[source]
Serializes the metadatum map to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
- __eq__(other)[source]
Checks equality with another MetadatumMap.
- Parameters:
other (object)
- Return type:
bool
- __contains__(key)[source]
Checks if a key is in the map. Accepts primitives.
- Parameters:
key (Metadatum | int | str | bytes | bytearray)
- Return type:
bool
- values()[source]
Returns an iterator over values (like Python dict).
- Return type:
Iterator[Metadatum]
- get_keys()[source]
Retrieves all keys from the map.
- Returns:
A MetadatumList containing all keys in the map.
- Raises:
CardanoError – If retrieval fails.
- Return type:
- get_values()[source]
Retrieves all values from the map.
- Returns:
A MetadatumList containing all values in the map.
- Raises:
CardanoError – If retrieval fails.
- Return type:
- __hash__ = None
- to_cip116_json(writer)[source]
Serializes this metadatum map to CIP-116 compliant JSON.
- Parameters:
writer (JsonWriter) – The JsonWriter to write the JSON to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None