NativeScript

class cometa.scripts.native_scripts.native_script.NativeScript(ptr)[source]

Bases: object

Represents a native script in Cardano.

Native scripts form an expression tree where the evaluation produces either true or false. They support signature requirements, time-locks, and boolean combinations (all, any, n-of-k).

Note that native scripts are recursive. There are no constraints on nesting or size, except that imposed by the overall transaction size limit.

__init__(ptr)[source]
Return type:

None

__enter__()[source]
Return type:

NativeScript

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

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_pubkey(script_pubkey)[source]

Creates a NativeScript from a ScriptPubkey.

Parameters:

script_pubkey (ScriptPubkey) – The ScriptPubkey to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_all(script_all)[source]

Creates a NativeScript from a ScriptAll.

Parameters:

script_all (ScriptAll) – The ScriptAll to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_any(script_any)[source]

Creates a NativeScript from a ScriptAny.

Parameters:

script_any (ScriptAny) – The ScriptAny to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_n_of_k(script_n_of_k)[source]

Creates a NativeScript from a ScriptNOfK.

Parameters:

script_n_of_k (ScriptNOfK) – The ScriptNOfK to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_invalid_before(script)[source]

Creates a NativeScript from a ScriptInvalidBefore.

Parameters:

script (ScriptInvalidBefore) – The ScriptInvalidBefore to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_invalid_after(script)[source]

Creates a NativeScript from a ScriptInvalidAfter.

Parameters:

script (ScriptInvalidAfter) – The ScriptInvalidAfter to wrap.

Returns:

A new NativeScript instance.

Raises:

CardanoError – If creation fails.

Return type:

NativeScript

classmethod from_cbor(reader)[source]

Deserializes a NativeScript from CBOR data.

Parameters:

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

Returns:

A new NativeScript deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

NativeScript

classmethod from_json(json)[source]

Creates a NativeScript from a JSON string.

Parameters:

json (str) – A JSON string containing the native script data.

Returns:

A new NativeScript deserialized from the JSON.

Raises:

CardanoError – If deserialization fails.

Return type:

NativeScript

to_cbor(writer)[source]

Serializes the native script to CBOR format.

Parameters:

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

Raises:

CardanoError – If serialization fails.

Return type:

None

property script_type: NativeScriptType

The type of this native script.

Returns:

The NativeScriptType value.

property hash: bytes

The hash of this native script.

Returns:

The 28-byte Blake2b hash.

to_pubkey()[source]

Converts this native script to a ScriptPubkey.

Returns:

The ScriptPubkey if this script is a pubkey script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptPubkey

to_all()[source]

Converts this native script to a ScriptAll.

Returns:

The ScriptAll if this script is an all script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptAll

to_any()[source]

Converts this native script to a ScriptAny.

Returns:

The ScriptAny if this script is an any script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptAny

to_n_of_k()[source]

Converts this native script to a ScriptNOfK.

Returns:

The ScriptNOfK if this script is an n-of-k script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptNOfK

to_invalid_before()[source]

Converts this native script to a ScriptInvalidBefore.

Returns:

The ScriptInvalidBefore if this script is an invalid_before script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptInvalidBefore

to_invalid_after()[source]

Converts this native script to a ScriptInvalidAfter.

Returns:

The ScriptInvalidAfter if this script is an invalid_after script.

Raises:

CardanoError – If conversion fails or type mismatch.

Return type:

ScriptInvalidAfter

__eq__(other)[source]

Checks equality with another NativeScript.

Parameters:

other (object)

Return type:

bool

__hash__ = None