WithdrawalMap
- class cometa.common.withdrawal_map.WithdrawalMap(ptr=None)[source]
Bases:
Mapping[RewardAddress, int]Represents a map of reward addresses to lovelace amounts.
This collection type is used for staking reward withdrawals in Cardano transactions and treasury withdrawal governance actions.
- classmethod from_cbor(reader)[source]
Deserializes a WithdrawalMap from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the withdrawal map data.
- Returns:
A new WithdrawalMap deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- to_cbor(writer)[source]
Serializes the withdrawal map to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
- classmethod from_dict(data)[source]
Creates a WithdrawalMap from a dictionary mapping Bech32 addresses to amounts.
- Parameters:
data (dict[str, int]) – A dictionary where keys are Bech32-encoded reward addresses (e.g., “stake1…”) and values are amounts in lovelace.
- Returns:
A new WithdrawalMap populated with the provided entries.
- Raises:
CardanoError – If creation or insertion fails.
- Return type:
Example
>>> withdrawals = WithdrawalMap.from_dict({ ... "stake_test1uq...": 1000000, ... "stake_test1up...": 2000000 ... })
- insert(key, value)[source]
Inserts or updates a reward address with its withdrawal amount.
- Parameters:
key (RewardAddress) – The reward address.
value (int) – The amount in lovelace to withdraw.
- Raises:
CardanoError – If insertion fails.
- Return type:
None
- insert_ex(reward_address, value)[source]
Inserts a withdrawal using a Bech32-encoded reward address string.
- Parameters:
reward_address (str) – Bech32-encoded reward address (e.g., “stake1…”).
value (int) – The amount in lovelace to withdraw.
- Raises:
CardanoError – If insertion fails.
- Return type:
None
- get(key, default=None)[source]
Retrieves the withdrawal amount for a given reward address.
- Parameters:
key (RewardAddress) – The reward address to look up.
default (int | None) – Value to return if key is not found. Defaults to None.
- Returns:
The withdrawal amount in lovelace, or default if not found.
- Return type:
int | None
- get_key_at(index)[source]
Retrieves the reward address at a specific index.
- Parameters:
index (int) – The index of the reward address to retrieve.
- Returns:
The RewardAddress at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- get_value_at(index)[source]
Retrieves the withdrawal amount at a specific index.
- Parameters:
index (int) – The index of the amount to retrieve.
- Returns:
The withdrawal amount in lovelace at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
int
- get_key_value_at(index)[source]
Retrieves the key-value pair at a specific index.
- Parameters:
index (int) – The index of the key-value pair to retrieve.
- Returns:
A tuple containing the RewardAddress and withdrawal amount at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
tuple[RewardAddress, int]
- get_keys()[source]
Retrieves all keys (reward addresses) from the map.
- Returns:
A RewardAddressList containing all reward addresses in the map.
- Raises:
CardanoError – If retrieval fails.
- Return type:
- __iter__()[source]
Iterates over all keys (like Python dict).
- Return type:
Iterator[RewardAddress]
- __getitem__(key)[source]
Gets a value by key using bracket notation.
- Parameters:
key (RewardAddress)
- Return type:
int
- __setitem__(key, value)[source]
Sets a value by key using bracket notation.
- Parameters:
key (RewardAddress)
value (int)
- Return type:
None
- __contains__(item)[source]
Checks if a reward address is in the map.
- Parameters:
item (RewardAddress)
- Return type:
bool
- keys()[source]
Returns an iterator over keys (like Python dict).
- Return type:
Iterator[RewardAddress]
- items()[source]
Returns an iterator over (key, value) pairs (like Python dict).
- Return type:
Iterator[Tuple[RewardAddress, int]]
- to_cip116_json(writer)[source]
Serializes this object to CIP-116 compliant JSON.
- Parameters:
writer (JsonWriter) – The JsonWriter to write the JSON to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None