abstract_cw1/
helpers.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, StdResult, WasmMsg};
3
4use crate::msg::Cw1ExecuteMsg;
5
6/// Cw1Contract is a wrapper around Addr that provides a lot of helpers
7/// for working with this.
8///
9/// If you wish to persist this, convert to Cw1CanonicalContract via .canonical()
10#[cw_serde]
11pub struct Cw1Contract(pub Addr);
12
13impl Cw1Contract {
14    pub fn addr(&self) -> Addr {
15        self.0.clone()
16    }
17
18    pub fn execute<T: Into<Vec<CosmosMsg>>>(&self, msgs: T) -> StdResult<CosmosMsg> {
19        let msg = Cw1ExecuteMsg::Execute { msgs: msgs.into() };
20        Ok(WasmMsg::Execute {
21            contract_addr: self.addr().into(),
22            msg: to_json_binary(&msg)?,
23            funds: vec![],
24        }
25        .into())
26    }
27}