Module

Trait Module 

Source
pub trait Module {
    type InstantiateMsg: for<'a> Deserialize<'a>;
    type ExecuteMsg: for<'a> Deserialize<'a>;
    type QueryMsg: for<'a> Deserialize<'a>;
    type QueryResp: Serialize;
    type Error: Display;

    // Required methods
    fn instantiate(
        &mut self,
        deps: &mut DepsMut<'_>,
        env: &Env,
        info: &MessageInfo,
        msg: Self::InstantiateMsg,
    ) -> Result<Response, Self::Error>;
    fn execute(
        &mut self,
        deps: &mut DepsMut<'_>,
        env: Env,
        info: MessageInfo,
        msg: Self::ExecuteMsg,
    ) -> Result<Response, Self::Error>;
    fn query(
        &self,
        deps: &Deps<'_>,
        env: Env,
        msg: Self::QueryMsg,
    ) -> Result<Self::QueryResp, Self::Error>;
}
Expand description

A well typed CosmWasm module

A module must implement instantiate, execute, and query handlers. These handlers may, however, be no-ops.

Programmers looking to implement reusable CosmWasm modules should create structs that implement Module.

Required Associated Types§

Source

type InstantiateMsg: for<'a> Deserialize<'a>

The message sent to the module to instantiate its state.

Source

type ExecuteMsg: for<'a> Deserialize<'a>

The type of transaction messages this module can handle. For modules that support multiple types of transaction, this will often times be a sum type.

Source

type QueryMsg: for<'a> Deserialize<'a>

The type of query messages this module can handle. For modules that support multiple queries, this will often times be a sum type.

Source

type QueryResp: Serialize

The response to queries dispatched to the module.

Source

type Error: Display

The type of errors this module can generate. This must implement Display for easy stringification.

Required Methods§

Source

fn instantiate( &mut self, deps: &mut DepsMut<'_>, env: &Env, info: &MessageInfo, msg: Self::InstantiateMsg, ) -> Result<Response, Self::Error>

The instantiate handler for the module. When a Manager with this module registered is instantiated, this method may be called.

Source

fn execute( &mut self, deps: &mut DepsMut<'_>, env: Env, info: MessageInfo, msg: Self::ExecuteMsg, ) -> Result<Response, Self::Error>

The transaction handler for this module. Messages to this contract will be dispatched by the Manager.

Source

fn query( &self, deps: &Deps<'_>, env: Env, msg: Self::QueryMsg, ) -> Result<Self::QueryResp, Self::Error>

The query handler for this module. Messages to this contract will be dispatched by the Manager.

Implementors§