Trait linera_sdk::Contract

source ·
pub trait Contract: WithContractAbi + ContractAbi + Sized {
    type Message: Serialize + DeserializeOwned + Debug;
    type Parameters: Serialize + DeserializeOwned + Clone + Debug;
    type InstantiationArgument: Serialize + DeserializeOwned + Debug;

    // Required methods
    async fn load(runtime: ContractRuntime<Self>) -> Self;
    async fn instantiate(&mut self, argument: Self::InstantiationArgument);
    async fn execute_operation(
        &mut self,
        operation: Self::Operation,
    ) -> Self::Response;
    async fn execute_message(&mut self, message: Self::Message);
    async fn store(self);
}
Expand description

The contract interface of a Linera application.

As opposed to the Service interface of an application, contract entry points are triggered by the execution of blocks in a chain. Their execution may modify storage and is gas-metered.

Below we use the word “transaction” to refer to the current operation or message being executed.

Required Associated Types§

source

type Message: Serialize + DeserializeOwned + Debug

The type of message executed by the application.

Messages are executed when a message created by the same application is received from another chain and accepted in a block.

source

type Parameters: Serialize + DeserializeOwned + Clone + Debug

Immutable parameters specific to this application (e.g. the name of a token).

source

type InstantiationArgument: Serialize + DeserializeOwned + Debug

Instantiation argument passed to a new application on the chain that created it (e.g. an initial amount of tokens minted).

To share configuration data on every chain, use Contract::Parameters instead.

Required Methods§

source

async fn load(runtime: ContractRuntime<Self>) -> Self

Creates an in-memory instance of the contract handler.

source

async fn instantiate(&mut self, argument: Self::InstantiationArgument)

Instantiates the application on the chain that created it.

This is only called once when the application is created and only on the microchain that created the application.

source

async fn execute_operation( &mut self, operation: Self::Operation, ) -> Self::Response

Applies an operation from the current block.

Operations are created by users and added to blocks, serving as the starting point for an application’s execution.

source

async fn execute_message(&mut self, message: Self::Message)

Applies a message originating from a cross-chain message.

Messages are sent across chains. These messages are created and received by the same application. Messages can be either single-sender and single-receiver, or single-sender and multiple-receivers. The former allows sending cross-chain messages to the application on some other specific chain, while the latter uses broadcast channels to send a message to multiple other chains where the application is subscribed to a sender channel on this chain.

For a message to be executed, a user must mark it to be received in a block of the receiver chain.

source

async fn store(self)

Finishes the execution of the current transaction.

This is called once at the end of the transaction, to allow all applications that participated in the transaction to perform any final operations, such as persisting their state.

The application may also cancel the transaction by panicking if there are any pendencies.

Object Safety§

This trait is not object safe.

Implementors§