PlutusV2ScriptList
- class cometa.auxiliary_data.plutus_v2_script_list.PlutusV2ScriptList(ptr=None)[source]
Bases:
Sequence[PlutusV2Script]Represents a list of Plutus V2 scripts.
Plutus scripts are pieces of code that implement pure functions with True or False outputs. These functions take several inputs such as Datum, Redeemer and the transaction context to decide whether an output can be spent or not.
V2 was introduced in the Vasil hard fork.
The main changes in V2 of Plutus were to the interface to scripts. The ScriptContext was extended to include the following information: - The full “redeemers” structure, which contains all the redeemers used in the transaction - Reference inputs in the transaction (proposed in CIP-31) - Inline datums in the transaction (proposed in CIP-32) - Reference scripts in the transaction (proposed in CIP-33)
Example
>>> from cometa import PlutusV2ScriptList >>> script_list = PlutusV2ScriptList() >>> script_list.add(script) >>> print(len(script_list)) 1
- __iter__()[source]
Iterates over all Plutus V2 scripts in the list.
- Return type:
Iterator[PlutusV2Script]
- __getitem__(index)[source]
Gets a Plutus V2 script by index using bracket notation.
- Parameters:
index (int)
- Return type:
- classmethod from_list(scripts)[source]
Creates a PlutusV2ScriptList from a Python list of PlutusV2Script objects.
- Parameters:
scripts (list[PlutusV2Script]) – A list of PlutusV2Script objects.
- Returns:
A new PlutusV2ScriptList containing all the scripts.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> script_list = PlutusV2ScriptList.from_list([script1, script2, script3])
- classmethod from_cbor(cbor_hex)[source]
Creates a PlutusV2ScriptList from a CBOR hex string.
- Parameters:
cbor_hex (str) – A hex-encoded CBOR string.
- Returns:
A new PlutusV2ScriptList decoded from the CBOR.
- Raises:
CardanoError – If decoding fails.
- Return type:
Example
>>> script_list = PlutusV2ScriptList.from_cbor("82...")
- to_cbor()[source]
Serializes the PlutusV2ScriptList to CBOR format.
- Returns:
A hex-encoded CBOR string.
- Raises:
CardanoError – If serialization fails.
- Return type:
str
Example
>>> cbor_hex = script_list.to_cbor()
- to_cip116_json(writer)[source]
Serializes the PlutusV2ScriptList to CIP-116 JSON format.
Writes a JSON array where each element is a Plutus V2 script object. This function emits the surrounding array brackets. Keys in each element are emitted in stable order: “language”, then “bytes”.
- Parameters:
writer – A JsonWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
Example
>>> from cometa import JsonWriter, JsonFormat >>> writer = JsonWriter(JsonFormat.COMPACT) >>> script_list.to_cip116_json(writer) >>> json_str = writer.encode()
- add(script)[source]
Adds a Plutus V2 script to the end of the list.
- Parameters:
script (PlutusV2Script) – The PlutusV2Script to add.
- Raises:
CardanoError – If addition fails.
- Return type:
None
- get(index)[source]
Retrieves a Plutus V2 script at the specified index.
- Parameters:
index (int) – The index of the script to retrieve.
- Returns:
The PlutusV2Script at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- append(script)[source]
Appends a Plutus V2 script to the end of the list.
This is an alias for add() to provide a more Pythonic interface.
- Parameters:
script (PlutusV2Script) – The PlutusV2Script to append.
- Raises:
CardanoError – If addition fails.
- Return type:
None
- index(value, start=0, stop=None)[source]
Returns the index of the first occurrence of value.
- Parameters:
value (PlutusV2Script) – The value to search for.
start (int) – Start searching from this index.
stop (int | None) – Stop searching at this index.
- Returns:
The index of the first occurrence.
- Raises:
ValueError – If the value is not found.
- Return type:
int
- count(value)[source]
Returns the number of occurrences of value.
- Parameters:
value (PlutusV2Script) – The value to count.
- Returns:
The number of occurrences.
- Return type:
int