ExUnits

class cometa.common.ex_units.ExUnits(ptr)[source]

Bases: object

Represents execution units for Plutus script execution.

Execution units measure the computational resources required to run a Plutus script on the Cardano blockchain. They consist of two components:

  • Memory: The amount of memory the script is expected to consume

  • CPU steps: The number of CPU steps the script is expected to require

These values are used to calculate transaction fees and ensure scripts don’t overrun system resources.

Example

>>> ex_units = ExUnits.new(memory=1000000, cpu_steps=500000000)
>>> ex_units.memory
1000000
__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

ExUnits

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

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod new(memory, cpu_steps)[source]

Creates new execution units with the specified memory and CPU steps.

Parameters:
  • memory (int) – The amount of memory (in units) for script execution.

  • cpu_steps (int) – The number of CPU steps for script execution.

Returns:

A new ExUnits instance.

Raises:

CardanoError – If creation fails.

Return type:

ExUnits

Example

>>> ex_units = ExUnits.new(1024, 500)
classmethod from_cbor(reader)[source]

Deserializes ExUnits from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the execution units data.

Returns:

A new ExUnits deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

ExUnits

property memory: int

Returns the memory component of the execution units.

property cpu_steps: int

Returns the CPU steps component of the execution units.

to_cbor(writer)[source]

Serializes the execution units to CBOR format.

Parameters:

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

Raises:

CardanoError – If serialization fails.

Return type:

None

to_cip116_json(writer)[source]

Converts this object to CIP-116 compliant JSON representation.

CIP-116 defines a standard JSON format for Cardano data structures.

Parameters:

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

Raises:

CardanoError – If conversion fails.

Return type:

None

__eq__(other)[source]

Checks equality with another ExUnits.

Parameters:

other (object)

Return type:

bool

__hash__()[source]

Returns a Python hash for use in sets and dicts.

Return type:

int

__str__()[source]

Returns a string representation of the execution units.

Return type:

str