Entry points
Entry points, or handlers are where messages or queries are handled by the contract.
All three of the functions we will be talking about are explicitly flagged as entry points, and excluded from being bundled in the library:
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, StdError> {
// ...etc
}
These handlers are:
- Instantiate messages, as defined by the
InstantiateMsg
struct, are handled byinstantiate
. - Messages, as defined by the
ExecuteMsg
enum, are handled by theexecute
function, using a pattern-matchingmatch
statement. - Queries, as defined by the
QueryMsg
enum, are handled by thequery
function, using a pattern-match.
execute
and query
must exhaustively match every variant in the enums they handle, while instantiate
only has to
deal with the struct it is passed.
Typically, instantiate
and execute
have the type Result<Response, ContractError>
, while query
has StdResult<Binary>
due to the underlying Cosmos SDK Querier
.