Andromeda
ADO LibraryBuild AppsDevelop ADOsCLIWeb Application Docs
Andromeda Archives
Andromeda Archives
  • Platform and Framework
    • Introduction to AndromedaOS
    • ADO Classes
    • Andromeda Messaging Protocol
      • Kernel
      • ADO Database
      • Economics Engine
      • Virtual File System
    • ADO Base
      • AndromedaMsg V1.0.0
      • AndromedaQuery V1.0.0
    • Common Types
    • Deployed Contracts
  • Andromeda Digital Objects
    • Introduction to ADOs
    • Auction V1.0.0
    • App V1.0.1
    • Crowdfund V1.0.0
    • CW20 V1.0.0
    • CW20 Staking V1.0.0
    • CW721 V1.0.0
    • CW20 Exchange V1.0.0
    • Lockdrop V1.0.0
    • Marketplace V1.0.0
    • Merkle-Airdrop V1.0.0
    • Rate Limiting Withdrawals V1.0.0
    • Splitter V1.0.0
    • Timelock V1.0.0
  • Andromeda Apps
    • Introduction to Apps
    • Crowdfunding App
    • Auctioning App
    • Cw20 Staking App
    • Marketplace App
  • Developing an ADO
    • Getting Started
      • Instantiation
      • Execution
      • Queries
      • Testing
    • ADO Example
    • ADO Submissions
  • Andromeda CLI
    • Introduction
    • Help and Shortcuts
    • ADO
    • Bank
    • Chain
    • Env
    • Gql
    • Tx
    • OS
    • Wallet
    • Wasm
    • Clearing CLI Data
    • Clear and Exit
  • Chain
    • Running a Node
    • Staking and Rewards
  • Andromeda Dashboard
    • Tokenomics Dashboard
    • Dashboard API
  • Additional Resources
    • GitHub
    • Website
    • White Paper
Powered by GitBook

Additional Resources

  • Github
  • Website

Community

  • Discord
  • Telegram

Socials

  • Twitter
  • Medium
  • Youtube
On this page

Was this helpful?

  1. Developing an ADO
  2. Getting Started

Execution

PreviousInstantiationNextQueries

Last updated 1 year ago

Was this helpful?

Execution

Executing messages in an ADO is a fairly simple process. We expose a new struct called ExecuteContext which has your regular dependencies, info and environment alongside a new struct (amp_ctx) that includes info about the current AMP packet if the message was received via the AMPReceive message type. An AMP Packet includes some useful information such as the origin field which includes the original sender of the packet. If you are using this for authorisation purposes please verify that the sender is someone you can trust.

pub struct ExecuteContext<'a> {
    pub deps: DepsMut<'a>,
    pub info: MessageInfo,
    pub env: Env,
    pub amp_ctx: Option<AMPPkt>,
}

In order to expose this data we must first call the method for handling AMPReceive messages and provide it your standard execution handler like so:

use andromeda_std::{ExecuteContext, ContractError};
// ..

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    msg: ExecuteMsg,
) -> Result<Response, ContractError> {
    let ctx = ExecuteContext::new(deps, info, env);
    if let ExecuteMsg::AMPReceive(pkt) = msg {
        ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute)
    } else {
        handle_execute(ctx, msg)
    }
}

pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
    match msg {
        // .. Your execute message handlers,
        ExecuteMsg::MyMsg { some_param } => my_handler(ctx, some_param),
        _ => ADOContract::default().execute(ctx, msg),
    }
}

pub fn my_handler(ctx: ExecuteContext, some_param: SomeVariableType) -> Result<Response, ContractError> {
    let ExecuteContext { amp_ctx, deps, info, env } = ctx;
    // .. Your code
}

Here we provide our handle_execute method to the execute_amp_receive method so that the handler can verify and create the ExecuteContext object appropriately before passing it to the handler.

As a catchall we provide the .execute(ctx, msg) call to handle any Andromeda specific messages. If you are looking to use another execute message handler such as cw721-base check out our CW721 contract .

AMPPkt
here