Attribute Macro cw_orch::interface

source ·
#[interface]
Expand description

Procedural macro to generate a cw-orchestrator interface

§Example

#[interface(
    cw20_base::msg::InstantiateMsg,
    cw20_base::msg::ExecuteMsg,
    cw20_base::msg::QueryMsg,
    cw20_base::msg::MigrateMsg
)]
pub struct Cw20;

This generated the following code:


// This struct represents the interface to the contract.
pub struct Cw20<Chain>(::cw_orch::prelude::Contract<Chain>);

impl <Chain> Cw20<Chain> {
    /// Constructor for the contract interface
     pub fn new(contract_id: impl ToString, chain: Chain) -> Self {
        Self(
            ::cw_orch::contract::Contract::new(contract_id, chain)
        )
    }
}

// Traits for signaling cw-orchestrator with what messages to call the contract's entry points.
impl <Chain> ::cw_orch::prelude::InstantiableContract for Cw20<Chain> {
    type InstantiateMsg = InstantiateMsg;
}
impl <Chain> ::cw_orch::prelude::ExecutableContract for Cw20<Chain> {
    type ExecuteMsg = ExecuteMsg;
}
// ... other entry point & upload traits

§Linking the interface to its source code

The interface can be linked to its source code by implementing the Uploadable trait for the interface.

use cw_orch::prelude::*;

impl <Chain> Uploadable for Cw20<Chain> {
    fn wrapper() -> <Mock as cw_orch::TxHandler>::ContractSource {
        Box::new(
            ContractWrapper::new_with_empty(
                cw20_base::contract::execute,
                cw20_base::contract::instantiate,
                cw20_base::contract::query,
            )
            .with_migrate(cw20_base::contract::migrate),
        )
    }

    fn wasm(_chain: &ChainInfoOwned) -> <Daemon as cw_orch::TxHandler>::ContractSource {
        WasmPath::new("path/to/cw20.wasm").unwrap()
    }
}