PlutusDataSet

class cometa.witness_set.plutus_data_set.PlutusDataSet(ptr=None)[source]

Bases: Set[PlutusData]

Represents a set of Plutus data.

Plutus data is used in Plutus scripts to carry additional information during script execution. The datum is a piece of data attached to UTXOs that scripts can use to validate transactions.

__init__(ptr=None)[source]
Return type:

None

__enter__()[source]
Return type:

PlutusDataSet

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

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_cbor(reader)[source]

Deserializes a PlutusDataSet from CBOR data.

Parameters:

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

Returns:

A new PlutusDataSet deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

PlutusDataSet

classmethod from_list(data_items)[source]

Creates a PlutusDataSet from an iterable of PlutusData objects.

Parameters:

data_items (Iterable[PlutusData]) – An iterable of PlutusData objects.

Returns:

A new PlutusDataSet containing all the data items.

Raises:

CardanoError – If creation fails.

Return type:

PlutusDataSet

to_cbor(writer)[source]

Serializes the data set to CBOR format.

Parameters:

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

Raises:

CardanoError – If serialization fails.

Return type:

None

add(data)[source]

Adds Plutus data to the set.

Parameters:

data (PlutusData) – The PlutusData to add.

Raises:

CardanoError – If addition fails.

Return type:

None

get(index)[source]

Retrieves Plutus data at the specified index.

Parameters:

index (int) – The index of the data to retrieve.

Returns:

The PlutusData at the specified index.

Raises:
  • CardanoError – If retrieval fails.

  • IndexError – If index is out of bounds.

Return type:

PlutusData

property use_tag: bool

Whether the set uses Conway era tagged encoding.

Returns:

True if using tagged encoding, False for legacy array encoding.

clear_cbor_cache()[source]

Clears the cached CBOR representation.

This is useful when you have modified the set after it was created from CBOR and you want to ensure that the next serialization reflects the current state rather than using the original cached CBOR.

Warning

Clearing the CBOR cache may change the binary representation when serialized, which can invalidate existing signatures.

Return type:

None

__len__()[source]

Returns the number of data items in the set.

Return type:

int

__iter__()[source]

Iterates over all data items in the set.

Return type:

Iterator[PlutusData]

__getitem__(index)[source]

Gets data by index using bracket notation.

Parameters:

index (int)

Return type:

PlutusData

__bool__()[source]

Returns True if the set is not empty.

Return type:

bool

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

__contains__(item)[source]

Checks if an item is in the set.

Parameters:

item (object)

Return type:

bool

isdisjoint(other)[source]

Returns True if the set has no elements in common with other.

Parameters:

other (Iterable[PlutusData]) – Another iterable to compare with.

Returns:

True if the sets are disjoint.

Return type:

bool