UtxoList
- class cometa.common.utxo_list.UtxoList(ptr=None)[source]
Bases:
Sequence[Utxo]Represents a list of UTxOs (Unspent Transaction Outputs).
This class provides a collection interface for managing multiple UTxOs, supporting standard list operations like iteration, indexing, and slicing.
Example
>>> from cometa import UtxoList, Utxo >>> utxo_list = UtxoList() >>> utxo_list.add(utxo) >>> print(len(utxo_list)) 1
- __getitem__(index)[source]
Gets a UTxO by index using bracket notation.
- Parameters:
index (int)
- Return type:
- classmethod from_list(utxos)[source]
Creates a UtxoList from a Python list of Utxo objects.
- Parameters:
utxos (list[Utxo]) – A list of Utxo objects.
- Returns:
A new UtxoList containing all the UTxOs.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> utxo_list = UtxoList.from_list([utxo1, utxo2, utxo3])
- add(utxo)[source]
Adds a UTxO to the end of the list.
- Parameters:
utxo (Utxo) – The Utxo to add.
- Raises:
CardanoError – If addition fails.
- Return type:
None
- get(index)[source]
Retrieves a UTxO at the specified index.
- Parameters:
index (int) – The index of the UTxO to retrieve.
- Returns:
The Utxo at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- remove(utxo)[source]
Removes a specific UTxO from the list.
- Parameters:
utxo (Utxo) – The Utxo to remove.
- Raises:
CardanoError – If removal fails or UTxO not found.
- Return type:
None
- clone()[source]
Creates a shallow clone of this UTxO list.
The cloned list contains references to the same UTxO elements. The UTxO elements themselves are not duplicated.
- Returns:
A new UtxoList containing the same elements.
- Return type:
- slice(start, end)[source]
Extracts a portion of the list between the given indices.
- Parameters:
start (int) – Start index of the slice (inclusive).
end (int) – End index of the slice (exclusive).
- Returns:
A new UtxoList containing the slice.
- Return type:
- erase(start, delete_count=1)[source]
Removes elements from the list starting at a given index.
This function removes delete_count elements from the list starting at the specified index and returns a new list containing the removed elements. The original list is modified in place.
- Parameters:
start (int) – The index at which to start removing elements. Supports negative indices (e.g., -1 for the last element).
delete_count (int) – The number of elements to remove from the list starting at start. If delete_count exceeds the number of elements from start to the end, it will be adjusted to remove till the end. Defaults to 1.
- Returns:
A new UtxoList containing the removed elements.
- Raises:
CardanoError – If the erase operation fails.
- Return type:
Example
>>> utxo_list = UtxoList.from_list([utxo1, utxo2, utxo3]) >>> removed = utxo_list.erase(1, 1) # Remove second element >>> print(len(utxo_list)) # Now has 2 elements 2 >>> print(len(removed)) # Removed list has 1 element 1
- index(value, start=0, stop=None)[source]
Returns the index of the first occurrence of value.
- Parameters:
value (Utxo) – 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