Skip to main content

luna.event

EventSourceType Objects

@enum.unique
class EventSourceType(str, enum.Enum)

Enumeration of various event source types

EventData Objects

@dataclass
class EventData()

Represents the fundamental data associated with an event within the Luna runtime environment. This data structure captures the essential aspects of an event, namely its name and payload.

Attributes:

  • name (str): The name of the event, used to identify and handle the event appropriately.
  • payload (PayloadDict): A dictionary containing the event's payload data. The payload holds specific details or parameters relevant to the event.

EventState Objects

@dataclass
class EventState()

Tracks and represents the state of an event within the Luna runtime environment. This state primarily includes information about which clauses have executed the event.

Attributes:

  • executed_by (Dict[str, datetime]): A mapping of clause names to the datetime instances when they executed this event. This attribute helps in understanding the event's interaction with different parts of the contract.

EventInstance Objects

@dataclass
class EventInstance()

Combines the event data and its state to form a complete representation of an event instance in the runtime. It is used within Luna's execution environment to maintain a comprehensive view of an event, including its unique identifier, data, state, and the time at which it was generated or processed.

The name EventInstance is used to disambiguate with the Event primitive used to create an abstract event in the Template. It therefore contains actual runtime data and state, as opposed to the Event which just contains the definition and type information.

Attributes:

  • uid (str): A unique identifier for the event instance.
  • data (EventData): The data associated with the event.
  • state (EventState): The state of the event, capturing execution details.
  • value_datetime (datetime): The datetime indicating when the event was generated or processed.

RuntimeEvent Objects

@dataclass
class RuntimeEvent()

Object used to pass an event to a clause at runtime, specifically when a clause is defined to react to an event. This class provides access to the event's unique identifier, name, and payload.

Example Usage:

@clause(on=Event(...))
def my_clause(self, event: RuntimeEvent):
pass
^---- `event` parameter is an instance of RuntimeEvent

Attributes:

  • uid (str): Unique identifier of the runtime event.
  • name (str): Name of the event.
  • payload (RuntimePayload): An object encapsulating the event's payload.

RuntimeClauseExecuted Objects

@dataclass
class RuntimeClauseExecuted()

Object used to pass information about the execution of one contract clause to another at runtime, especially in scenarios where one clause's execution is dependent on another's.

Example Usage:

@clause(on=ClauseExecuted(...))
def my_clause(self, clause: RuntimeClauseExecuted):
pass
^---- `clause` parameter is an instance of RuntimeClauseExecuted

Attributes:

  • event_id (str): The identifier of the event associated with the clause execution.
  • name (str): The name of the executed clause.
  • eval_count (int): The count of evaluations or executions of the clause.
  • output (Any): The output produced by the clause, if any.