PolicyIdList

class cometa.assets.policy_id_list.PolicyIdList(ptr=None)[source]

Bases: Sequence[Blake2bHash]

Represents a list of policy IDs (Blake2b-224 hashes).

Policy IDs are used to identify minting policies in Cardano.

Example

>>> policy_list = PolicyIdList()
>>> policy_list.add(Blake2bHash.from_hex("00" * 28))
>>> len(policy_list)
1
__init__(ptr=None)[source]
Return type:

None

classmethod from_list(policy_ids)[source]

Creates a PolicyIdList from an iterable of Blake2bHash objects.

Parameters:

policy_ids (Iterable[Blake2bHash]) – An iterable of Blake2bHash objects (policy IDs).

Returns:

A new PolicyIdList containing all the policy IDs.

Raises:

CardanoError – If creation fails.

Return type:

PolicyIdList

__enter__()[source]
Return type:

PolicyIdList

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

None

__repr__()[source]

Return repr(self).

Return type:

str

add(element)[source]

Adds a policy ID to the list.

Parameters:

element (Blake2bHash) – The policy ID (Blake2b-224 hash) to add.

Raises:

CardanoError – If the operation fails.

Return type:

None

get(index)[source]

Retrieves a policy ID by index.

Parameters:

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

Returns:

The policy ID (Blake2bHash) at the specified index.

Raises:
  • CardanoError – If retrieval fails.

  • IndexError – If index is out of bounds.

Return type:

Blake2bHash

__len__()[source]

Returns the number of elements in the list.

Return type:

int

__iter__()[source]

Iterates over all policy IDs in the list.

Return type:

Iterator[Blake2bHash]

__getitem__(index)[source]

Gets a policy ID by index using bracket notation. Supports negative indices.

Parameters:

index (int)

Return type:

Blake2bHash

__contains__(item)[source]

Checks if a policy ID is in the list.

Parameters:

item (Blake2bHash)

Return type:

bool

__bool__()[source]

Returns True if the list is not empty.

Return type:

bool

append(element)[source]

Appends a policy ID to the list.

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

Parameters:

element (Blake2bHash) – The policy ID to append.

Return type:

None

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

Returns the index of the first occurrence of value.

Parameters:
  • value (Blake2bHash) – 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 (Blake2bHash) – The value to count.

Returns:

The number of occurrences.

Return type:

int