Costmdls

class cometa.protocol_params.costmdls.Costmdls(ptr)[source]

Bases: object

A collection of cost models for different Plutus language versions.

This class holds a map of Plutus language versions to their respective cost models. It provides methods to insert, retrieve, and check for cost models by language version.

__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

Costmdls

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

None

__repr__()[source]

Return repr(self).

Return type:

str

__contains__(language)[source]

Checks if a cost model exists for the given language version.

Parameters:

language (PlutusLanguageVersion)

Return type:

bool

__getitem__(language)[source]

Gets the cost model for a specific language version.

Parameters:

language (PlutusLanguageVersion) – The Plutus language version.

Returns:

The CostModel for that version.

Raises:

KeyError – If no cost model exists for the language.

Return type:

CostModel

__setitem__(language, model)[source]

Sets the cost model for a language version.

Note: The language version is determined by the model itself.

Parameters:
Return type:

None

classmethod new()[source]

Creates a new empty Costmdls collection.

Returns:

A new empty Costmdls instance.

Raises:

CardanoError – If creation fails.

Return type:

Costmdls

classmethod from_cbor(reader)[source]

Deserializes Costmdls from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the costmdls data.

Returns:

A new Costmdls deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

Costmdls

to_cbor(writer)[source]

Serializes the costmdls to CBOR format.

Parameters:

writer (CborWriter) – A CborWriter to write the serialized data to.

Raises:

CardanoError – If serialization fails.

Return type:

None

insert(cost_model)[source]

Inserts a cost model into the collection.

The language version is determined by the cost model itself.

Parameters:

cost_model (CostModel) – The CostModel to insert.

Raises:

CardanoError – If insertion fails.

Return type:

None

get(language)[source]

Retrieves a cost model for a specific language version.

Parameters:

language (PlutusLanguageVersion) – The Plutus language version.

Returns:

The CostModel if found, None otherwise.

Return type:

CostModel | None

has(language)[source]

Checks if a cost model exists for a specific language version.

Parameters:

language (PlutusLanguageVersion) – The Plutus language version to check.

Returns:

True if a cost model exists, False otherwise.

Return type:

bool

get_language_views_encoding()[source]

Gets the language views encoding for computing script data hash.

This encodes the cost models following the CDDL specification, necessary for computing the script data hash of a transaction.

Returns:

A Buffer containing the encoded language views.

Raises:

CardanoError – If encoding fails.

Return type:

Buffer

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