Andromeda
ADO LibraryBuild AppsDevelop ADOsCLIWeb Application Docs
Andromeda
Andromeda
  • Platform and Framework
    • Introduction to AndromedaOS
    • ADO Classes
    • Andromeda Messaging Protocol
      • Kernel
      • ADO Database
      • Economics Engine
      • Virtual File System
    • ADO Base
      • AndromedaMsg
      • AndromedaQuery
    • Common Types
    • Deployed Contracts
    • ADO Versions
  • Andromeda Digital Objects
    • Introduction to ADOs
    • Address List
    • Auction
    • App
    • Curve
    • CW20
    • CW20 Staking
    • CW721
    • CW20 Exchange
    • Fixed Amount Splitter
    • Graph
    • Lockdrop
    • Marketplace
    • Merkle-Airdrop
    • Point
    • Primitive
    • Rates
    • Splitter
    • Timelock
    • Validator Staking
    • Vesting
  • Andromeda Apps
    • Introduction to Apps
    • Auctioning App
    • Cw20 Staking App
    • Marketplace App
  • Developing an ADO
    • Getting Started
      • Instantiation
      • Execution
      • Queries
      • Testing
    • Error Handling and Migrate Function
    • CW3 EXAMPLE
      • InstantiateMsg
      • ExecuteMsg
      • QueryMsg
      • Testing
    • 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
  • Andromeda Changelog
    • Newest Releases
  • Additional Resources
    • GitHub
    • Website
    • White Paper
Powered by GitBook

Additional Resources

  • Github
  • Website

Community

  • Discord
  • Telegram

Socials

  • Twitter
  • Medium
  • Youtube
On this page
  • Execution
  • Attributes

Was this helpful?

  1. Developing an ADO
  2. Getting Started

Execution

PreviousInstantiationNextQueries

Last updated 2 months 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>,
    pub contract: ADOContract<'a>,
    pub raw_info: MessageInfo,
}

In order to expose this data we must first call the method for handling AMPReceive messages and provide it your standard execution handler. This is done by our andr_execute_fn macro:

contract.rs
#[andromeda_std::andr_execute_fn]
pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
    match msg {
        // .. Your execute message handlers,
        _ => ADOContract::default().execute(ctx, msg)
    }
}


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

Attributes

There are a lot of cases where we want messages to have specific validation checks, these validation checks are usually extremely common and add a bit of overhead to implement and validate. To reduce this some of these redundant checks have been moved to "attributes". These are field attributes on the ExecuteMsg variants that define what validation should occur when the message is called (even when it is called via AMP). These include:

Atrribute
Description

nonpayable

This message should not accept funds.

restricted

This message should only be callable by the contract owner.

direct

This messae should not be callable via AMP.

msg.rs
pub enum ExecuteMsg {
  #[attrs(restricted, nonpayable)]
  MyRestrictedMsg { //.. }.
  #[attrs(direct)]
  MyDirectMsg { //.. },
}

These can be applied in any particular order or combination. The checks for these are then performed using the andr_execute_fn macro so they do not require any extra code, however they do add methods to the ExecuteMsg enum that may be used as necessary.

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