Skip to main content

luna.base

This module in the Luna SDK provides a set of abstract base classes and utilities designed for building and interacting with Luna smart contracts. It includes mechanisms for state management, runtime initialization, dynamic value handling, and custom exception definitions. These tools are essential for developers to effectively create, manipulate, and maintain the state and behavior of smart contracts within the Luna ecosystem.

NoValue Objects

class NoValue()

Represents the absence of value. This allows the user to use None as they see fit without us using it.

Stateful Objects

class Stateful(ABC)

Gives access to the runtime state as self.state. This class serves as a hook for injecting the state through the set_state method at runtime.

NOTE: the state will only be accessible at runtime within the context of a Luna contract.

Named Objects

class Named(ABC)

Gives access to the variable name as self.name. For example, given a class Foo deriving from Named and the following snippet:

my_var_name = Foo()

Within Foo, self.name will be accessible and will have value my_var_name.

NOTE: the value will only be accessible at runtime within the context of a Luna contract.

RuntimeInit Objects

class RuntimeInit(ABC)

Allow to initialise a class during the Luna runtime init and not the class init. Method runtime_init will be called once within the Luna runtime context at the start of contract execution.

Valuable Objects

class Valuable(ABC, Generic[T])

Used to contain a value of any type supported by Luna. The value is stored locally.

StateValuable Objects

class StateValuable(Valuable[T], Stateful)

Used to contain a value of any type supported by Luna. The value is stored within the state.

set_value and get_value must be overridden to specify how to get the value from state.