1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{
3 to_json_binary, Addr, Coin, ContractInfoResponse, CustomQuery, Querier, QuerierWrapper,
4 StdResult, WasmMsg, WasmQuery,
5};
6use sg_std::CosmosMsg;
7
8use crate::msg::ExecuteMsg;
9
10#[cw_serde]
13pub struct MinterContract(pub Addr);
14
15impl MinterContract {
16 pub fn addr(&self) -> Addr {
17 self.0.clone()
18 }
19
20 pub fn call<T: Into<ExecuteMsg>>(&self, msg: T) -> StdResult<CosmosMsg> {
21 let msg = to_json_binary(&msg.into())?;
22 Ok(WasmMsg::Execute {
23 contract_addr: self.addr().into(),
24 msg,
25 funds: vec![],
26 }
27 .into())
28 }
29
30 pub fn call_with_funds<T: Into<ExecuteMsg>>(
31 &self,
32 msg: T,
33 funds: Coin,
34 ) -> StdResult<CosmosMsg> {
35 let msg = to_json_binary(&msg.into())?;
36 Ok(WasmMsg::Execute {
37 contract_addr: self.addr().into(),
38 msg,
39 funds: vec![funds],
40 }
41 .into())
42 }
43
44 pub fn contract_info<Q, T, CQ>(&self, querier: &Q) -> StdResult<ContractInfoResponse>
45 where
46 Q: Querier,
47 T: Into<String>,
48 CQ: CustomQuery,
49 {
50 let query = WasmQuery::ContractInfo {
51 contract_addr: self.addr().into(),
52 }
53 .into();
54 let res: ContractInfoResponse = QuerierWrapper::<CQ>::new(querier).query(&query)?;
55 Ok(res)
56 }
57}