CostModel
- class cometa.protocol_params.cost_model.CostModel(ptr)[source]
Bases:
objectRepresents a cost model for Plutus script execution.
The execution of Plutus scripts consumes resources. Cost models provide predictable pricing for script execution by defining the computational cost of each operation in the Plutus language.
A cost model is associated with a specific Plutus language version (V1, V2, V3) and contains an array of costs for each operation.
- __getitem__(operation)[source]
Gets the cost for a specific operation index.
- Parameters:
operation (int) – The operation index.
- Returns:
The cost for that operation.
- Raises:
KeyError – If the operation index is out of range.
- Return type:
int
- __setitem__(operation, cost)[source]
Sets the cost for a specific operation index.
- Parameters:
operation (int) – The operation index.
cost (int) – The cost value.
- Raises:
KeyError – If the operation index is out of range.
- Return type:
None
- classmethod new(language, costs)[source]
Creates a new cost model for a specific Plutus language version.
- Parameters:
language (PlutusLanguageVersion) – The Plutus language version.
costs (List[int]) – A list of costs for each operation.
- Returns:
A new CostModel instance.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> costs = [100000, 200000, ...] # Operation costs >>> model = CostModel.new(PlutusLanguageVersion.V1, costs)
- classmethod from_cbor(reader)[source]
Deserializes a CostModel from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the cost model data.
- Returns:
A new CostModel deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- to_cbor(writer)[source]
Serializes the cost model to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
- property language: PlutusLanguageVersion
Returns the Plutus language version for this cost model.
- Returns:
The PlutusLanguageVersion of this cost model.
- get_cost(operation)[source]
Gets the cost for a specific operation index.
- Parameters:
operation (int) – The operation index (0-based).
- Returns:
The cost for that operation.
- Raises:
CardanoError – If retrieval fails.
- Return type:
int
- set_cost(operation, cost)[source]
Sets the cost for a specific operation index.
- Parameters:
operation (int) – The operation index (0-based).
cost (int) – The cost value to set.
- Raises:
CardanoError – If setting fails.
- Return type:
None
- get_costs()[source]
Returns all costs in the model as a list.
- Returns:
A list of costs for all operations.
- Return type:
List[int]
- to_cip116_json(writer)[source]
Serializes this cost model to CIP-116 compliant JSON.
- Parameters:
writer (JsonWriter) – The JsonWriter to write the JSON to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None