MetadatumList

class cometa.auxiliary_data.metadatum_list.MetadatumList(ptr=None)[source]

Bases: Sequence[Metadatum]

Represents a list of metadatum values.

Used to construct list-type metadata in transactions. Accepts Python primitives (int, str, bytes) directly.

Example

>>> meta_list = MetadatumList()
>>> meta_list.add(1)              # int
>>> meta_list.add("hello")        # str
>>> meta_list.add(b"\xde\xad")    # bytes
>>> len(meta_list)
3
>>> 1 in meta_list
True
__init__(ptr=None)[source]
Return type:

None

classmethod from_list(elements)[source]

Creates a MetadatumList from an iterable of metadatum values.

Parameters:

elements (Iterable[Metadatum | int | str | bytes | bytearray]) – An iterable of Metadatum objects or Python primitives (int, str, bytes, bytearray).

Returns:

A new MetadatumList containing all the elements.

Raises:

CardanoError – If creation fails.

Return type:

MetadatumList

__enter__()[source]
Return type:

MetadatumList

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_cbor(reader)[source]

Deserializes a MetadatumList from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the list data.

Returns:

A new MetadatumList deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

MetadatumList

add(element)[source]

Adds a metadatum to the list.

Parameters:

element (Metadatum | int | str | bytes | bytearray) – The metadatum to add. Can be a Metadatum object or a Python primitive (int, str, bytes, bytearray).

Raises:
  • CardanoError – If the operation fails.

  • TypeError – If element cannot be converted to Metadatum.

Return type:

None

Example

>>> meta_list = MetadatumList()
>>> meta_list.add(42)           # int
>>> meta_list.add("hello")      # str
>>> meta_list.add(b"\xde\xad")  # bytes
get(index)[source]

Retrieves a metadatum by index.

Parameters:

index (int) – The index of the element to retrieve.

Returns:

The Metadatum at the specified index.

Raises:
  • CardanoError – If retrieval fails.

  • IndexError – If index is out of bounds.

Return type:

Metadatum

to_cbor(writer)[source]

Serializes the metadatum list to CBOR format.

Parameters:

writer (CborWriter) – A CborWriter to write the serialized data to.

Raises:

CardanoError – If serialization fails.

Return type:

None

__len__()[source]

Returns the number of elements in the list.

Return type:

int

__iter__()[source]

Iterates over all metadatum values in the list.

Return type:

Iterator[Metadatum]

__getitem__(index)[source]

Gets a metadatum by index using bracket notation. Supports negative indices.

Parameters:

index (int)

Return type:

Metadatum

__eq__(other)[source]

Checks equality with another MetadatumList.

Parameters:

other (object)

Return type:

bool

__bool__()[source]

Returns True if the list is not empty.

Return type:

bool

__contains__(item)[source]

Checks if a metadatum is in the list. Accepts primitives.

Parameters:

item (Metadatum | int | str | bytes | bytearray)

Return type:

bool

append(element)[source]

Appends a metadatum to the list.

This is an alias for add() to match Python list semantics.

Parameters:

element (Metadatum | int | str | bytes | bytearray) – The metadatum to append. Can be a Metadatum object or a Python primitive (int, str, bytes, bytearray).

Return type:

None

to_cip116_json(writer)[source]

Serializes this metadatum list to CIP-116 compliant JSON.

Parameters:

writer (JsonWriter) – The JsonWriter to write the JSON to.

Raises:

CardanoError – If serialization fails.

Return type:

None

index(value, start=0, stop=None)[source]

Returns the index of the first occurrence of value.

Parameters:
  • value (Metadatum) – The value to search for.

  • start (int) – Start searching from this index.

  • stop (int | None) – Stop searching at this index.

Returns:

The index of the first occurrence.

Raises:

ValueError – If the value is not found.

Return type:

int

count(value)[source]

Returns the number of occurrences of value.

Parameters:

value (Metadatum) – The value to count.

Returns:

The number of occurrences.

Return type:

int

__hash__ = None