pub trait Contract:
WithContractAbi
+ ContractAbi
+ Sized {
type Message: Serialize + DeserializeOwned + Debug;
type Parameters: Serialize + DeserializeOwned + Clone + Debug;
type InstantiationArgument: Serialize + DeserializeOwned + Debug;
type EventValue: 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);
// Provided method
async fn process_streams(&mut self, _updates: Vec<StreamUpdate>) { ... }
}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. Operations are created by users and added to blocks, serving as the starting point for an application’s execution. Messages are executed when a message created by the same application is received from another chain and accepted in a block.
instantiate is only called once when the application is created and only on the
microchain that created the application. To share configuration data on every chain,
use Contract::Parameters instead of Contract::InstantiationArgument.
Messages are meant to be sent across chains. They are created and received by the same application. For a message to be executed, a user must mark it to be received in a block of the receiver chain.
store 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.
Required Associated Types§
Sourcetype Message: Serialize + DeserializeOwned + Debug
type Message: Serialize + DeserializeOwned + Debug
The type of message executed by the application.
Sourcetype Parameters: Serialize + DeserializeOwned + Clone + Debug
type Parameters: Serialize + DeserializeOwned + Clone + Debug
Immutable parameters specific to this application (e.g. the name of a token).
Sourcetype InstantiationArgument: Serialize + DeserializeOwned + Debug
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).
Sourcetype EventValue: Serialize + DeserializeOwned + Debug
type EventValue: Serialize + DeserializeOwned + Debug
Event values for streams created by this application.
Required Methods§
Sourceasync fn load(runtime: ContractRuntime<Self>) -> Self
async fn load(runtime: ContractRuntime<Self>) -> Self
Creates an in-memory instance of the contract handler.
Sourceasync fn instantiate(&mut self, argument: Self::InstantiationArgument)
async fn instantiate(&mut self, argument: Self::InstantiationArgument)
Instantiates the application on the chain that created it.
Sourceasync fn execute_operation(
&mut self,
operation: Self::Operation,
) -> Self::Response
async fn execute_operation( &mut self, operation: Self::Operation, ) -> Self::Response
Applies an operation from the current block.
Sourceasync fn execute_message(&mut self, message: Self::Message)
async fn execute_message(&mut self, message: Self::Message)
Applies a message originating from a cross-chain message.
Provided Methods§
Sourceasync fn process_streams(&mut self, _updates: Vec<StreamUpdate>)
async fn process_streams(&mut self, _updates: Vec<StreamUpdate>)
Reacts to new events on streams.
This is called whenever there is a new event on any stream that this application subscribes to.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.