InputToRedeemerMap

class cometa.transaction_builder.balancing.input_to_redeemer_map.InputToRedeemerMap(ptr=None)[source]

Bases: Mapping[TransactionInput, Redeemer]

A map of transaction inputs to redeemers.

This map associates specific references of inputs to redeemers in the witness set. Balancing the transaction can add additional inputs and this can make inputs change positions in the input set. Redeemers must be updated to point to the correct input.

If you provide redeemers for any pre-selected input, you must specify this association in this map.

Example

>>> from cometa.transaction_builder.balancing import InputToRedeemerMap
>>> from cometa.transaction_body import TransactionInput
>>> from cometa.witness_set import Redeemer
>>>
>>> input_map = InputToRedeemerMap.new()
>>> input_map.insert(tx_input, redeemer)
>>> print(f"Map contains {len(input_map)} entries")
__init__(ptr=None)[source]
Return type:

None

__enter__()[source]
Return type:

InputToRedeemerMap

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

None

__repr__()[source]

Return repr(self).

Return type:

str

__len__()[source]
Return type:

int

__iter__()[source]

Iterate over keys (TransactionInputs).

Return type:

Iterator[‘TransactionInput’]

classmethod new()[source]

Create a new empty InputToRedeemerMap.

Returns:

A new InputToRedeemerMap instance.

Raises:

CardanoError – If creation fails.

Return type:

InputToRedeemerMap

insert(key, value)[source]

Insert a key-value pair into the map.

Parameters:
  • key (TransactionInput) – The transaction input to use as key.

  • value (Redeemer) – The redeemer to associate with the input.

Raises:

CardanoError – If insertion fails.

Return type:

None

__getitem__(key)[source]

Get the redeemer associated with a transaction input.

Parameters:

key (TransactionInput) – The transaction input to look up.

Returns:

The associated redeemer.

Raises:
  • KeyError – If key is not found.

  • CardanoError – If lookup fails.

Return type:

Redeemer

get(key, default=None)[source]

Get the redeemer associated with a transaction input.

Parameters:
  • key (TransactionInput) – The transaction input to look up.

  • default (Optional['Redeemer']) – Value to return if key is not found.

Returns:

The associated redeemer, or default if not found.

Return type:

Optional[‘Redeemer’]

get_key_at(index)[source]

Get the transaction input at the specified index.

Parameters:

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

Returns:

The TransactionInput at the specified index.

Raises:

CardanoError – If retrieval fails.

Return type:

TransactionInput

get_value_at(index)[source]

Get the redeemer at the specified index.

Parameters:

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

Returns:

The Redeemer at the specified index.

Raises:

CardanoError – If retrieval fails.

Return type:

Redeemer

get_key_value_at(index)[source]

Get both the key and value at the specified index.

Parameters:

index (int) – The index of the key-value pair to retrieve.

Returns:

A tuple of (TransactionInput, Redeemer) at the specified index.

Raises:

CardanoError – If retrieval fails.

Return type:

Tuple[‘TransactionInput’, ‘Redeemer’]

update_redeemer_index(tx_input, new_index)[source]

Update the index of a redeemer that matches the given input.

If a matching redeemer is found, its index is updated. Otherwise, nothing happens.

Parameters:
  • tx_input (TransactionInput) – The input key to search for.

  • new_index (int) – The new index to assign to the redeemer.

Raises:

CardanoError – If update fails.

Return type:

None

get_last_error()[source]

Get the last error message recorded for this map.

Returns:

The last error message, or empty string if none.

Return type:

str