CoinSelector

class cometa.transaction_builder.coin_selection.coin_selector.CoinSelectorProtocol(*args, **kwargs)[source]

Bases: Protocol

Protocol defining the interface for coin selection strategies.

Coin selection is the process of selecting UTXOs (Unspent Transaction Outputs) to meet a target transaction value while optimizing for factors like: - Minimizing the number of inputs (to reduce fees) - Reducing dust (small UTXOs) - Optimizing change output size

Implement this protocol to create custom coin selection strategies.

Example

>>> class MyCustomSelector:
...     def get_name(self) -> str:
...         return "MyCustomSelector"
...
...     def select(
...         self,
...         pre_selected_utxo: List[Utxo],
...         available_utxo: List[Utxo],
...         target: Value,
...     ) -> Tuple[List[Utxo], List[Utxo]]:
...         # Custom selection logic
...         selected = []
...         remaining = list(available_utxo)
...         # ... selection algorithm ...
...         return selected, remaining
get_name()[source]

Get the human-readable name of this coin selector.

Returns:

The coin selector name (e.g., “LargeFirst”, “RandomImprove”).

Return type:

str

select(pre_selected_utxo, available_utxo, target)[source]

Select UTXOs to satisfy the target value.

This method should implement the coin selection algorithm, choosing UTXOs from the available set to meet the target value.

Parameters:
  • pre_selected_utxo (Union['UtxoList', List['Utxo']]) – UTXOs that must be included in the selection.

  • available_utxo (Union['UtxoList', List['Utxo']]) – Available UTXOs to choose from.

  • target (Value) – The target value to satisfy (ADA and/or multi-assets).

Returns:

A tuple of (selected_utxos, remaining_utxos).

Raises:

Exception – If selection fails (e.g., insufficient funds).

Return type:

Tuple[List[‘Utxo’], List[‘Utxo’]]

__init__(*args, **kwargs)
cometa.transaction_builder.coin_selection.coin_selector.CoinSelector

alias of CoinSelectorProtocol