PlutusV1ScriptList
- class cometa.auxiliary_data.plutus_v1_script_list.PlutusV1ScriptList(ptr=None)[source]
Bases:
Sequence[PlutusV1Script]Represents a list of Plutus V1 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.
V1 was the initial version of Plutus, introduced in the Alonzo hard fork.
Example
>>> from cometa import PlutusV1ScriptList >>> script_list = PlutusV1ScriptList() >>> script_list.add(script) >>> print(len(script_list)) 1
- __iter__()[source]
Iterates over all Plutus V1 scripts in the list.
- Return type:
Iterator[PlutusV1Script]
- __getitem__(index)[source]
Gets a Plutus V1 script by index using bracket notation.
- Parameters:
index (int)
- Return type:
- classmethod from_list(scripts)[source]
Creates a PlutusV1ScriptList from a Python list of PlutusV1Script objects.
- Parameters:
scripts (list[PlutusV1Script]) – A list of PlutusV1Script objects.
- Returns:
A new PlutusV1ScriptList containing all the scripts.
- Raises:
CardanoError – If creation fails.
- Return type:
Example
>>> script_list = PlutusV1ScriptList.from_list([script1, script2, script3])
- classmethod from_cbor(cbor_hex)[source]
Creates a PlutusV1ScriptList from a CBOR hex string.
- Parameters:
cbor_hex (str) – A hex-encoded CBOR string.
- Returns:
A new PlutusV1ScriptList decoded from the CBOR.
- Raises:
CardanoError – If decoding fails.
- Return type:
Example
>>> script_list = PlutusV1ScriptList.from_cbor("82...")
- to_cbor()[source]
Serializes the PlutusV1ScriptList to CBOR format.
- Returns:
A hex-encoded CBOR string.
- Raises:
CardanoError – If serialization fails.
- Return type:
str
Example
>>> cbor_hex = script_list.to_cbor()
- add(script)[source]
Adds a Plutus V1 script to the end of the list.
- Parameters:
script (PlutusV1Script) – The PlutusV1Script to add.
- Raises:
CardanoError – If addition fails.
- Return type:
None
- get(index)[source]
Retrieves a Plutus V1 script at the specified index.
- Parameters:
index (int) – The index of the script to retrieve.
- Returns:
The PlutusV1Script at the specified index.
- Raises:
CardanoError – If retrieval fails.
IndexError – If index is out of bounds.
- Return type:
- to_cip116_json(writer)[source]
Serializes the PlutusV1ScriptList to CIP-116 JSON format.
Writes a JSON array where each element is a Plutus v1 script object with the shape: [
{ “language”: “plutus_v1”, “bytes”: “<hex-bytes>” }, { “language”: “plutus_v1”, “bytes”: “<hex-bytes>” }
]
This method emits the surrounding array brackets ([and ]). It does not write a property name; if you need this list as a field value inside another object, write the property name first and then call this method.
- Parameters:
writer – A JsonWriter instance where the JSON will be written.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
Example
>>> from cometa import JsonWriter, JsonFormat >>> writer = JsonWriter(JsonFormat.COMPACT) >>> script_list.to_cip116_json(writer)
- append(script)[source]
Appends a Plutus V1 script to the end of the list.
This is an alias for add() to provide a more Pythonic interface.
- Parameters:
script (PlutusV1Script) – The PlutusV1Script 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 (PlutusV1Script) – 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 (PlutusV1Script) – The value to count.
- Returns:
The number of occurrences.
- Return type:
int