counter_contract/
interface.rs

1use cw_orch::daemon::queriers::Node;
2use cw_orch::environment::ChainInfoOwned;
3// ANCHOR: custom_interface
4use cw_orch::{interface, prelude::*};
5
6use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
7
8pub const CONTRACT_ID: &str = "counter_contract";
9
10// ANCHOR: interface_macro
11#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg, id = CONTRACT_ID)]
12pub struct CounterContract;
13// ANCHOR_END: interface_macro
14
15// ANCHOR: uploadable_impl
16impl<Chain> Uploadable for CounterContract<Chain> {
17    /// Return the path to the wasm file corresponding to the contract
18    fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
19        artifacts_dir_from_workspace!()
20            .find_wasm_path("counter_contract")
21            .unwrap()
22    }
23    /// Returns a CosmWasm contract wrapper
24    fn wrapper() -> Box<dyn MockContract<Empty>> {
25        Box::new(
26            ContractWrapper::new_with_empty(
27                crate::contract::execute,
28                crate::contract::instantiate,
29                crate::contract::query,
30            )
31            .with_migrate(crate::contract::migrate),
32        )
33    }
34}
35// ANCHOR_END: uploadable_impl
36// ANCHOR_END: custom_interface
37
38use cw_orch::anyhow::Result;
39
40// ANCHOR: daemon
41impl CounterContract<Daemon> {
42    /// Deploys the counter contract at a specific block height
43    pub fn await_launch(&self) -> Result<()> {
44        let daemon = self.environment();
45
46        // Get the node query client, there are a lot of other clients available.
47        let node: Node = daemon.querier();
48        let mut latest_block = node.latest_block().unwrap();
49
50        while latest_block.height < 100 {
51            // wait for the next block
52            daemon.next_block().unwrap();
53            latest_block = node.latest_block().unwrap();
54        }
55
56        let contract = CounterContract::new(daemon.clone());
57
58        // Upload the contract
59        contract.upload().unwrap();
60
61        // Instantiate the contract
62        let msg = InstantiateMsg { count: 1i32 };
63        contract.instantiate(&msg, None, &[]).unwrap();
64
65        Ok(())
66    }
67}
68// ANCHOR_END: daemon