1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{to_binary, Api, CanonicalAddr, CosmosMsg, HumanAddr, StdResult, WasmMsg};
use crate::msg::Cw1HandleMsg;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Cw1Contract(pub HumanAddr);
impl Cw1Contract {
pub fn addr(&self) -> HumanAddr {
self.0.clone()
}
pub fn canonical<A: Api>(&self, api: &A) -> StdResult<Cw1CanonicalContract> {
let canon = api.canonical_address(&self.0)?;
Ok(Cw1CanonicalContract(canon))
}
pub fn execute<T: Into<Vec<CosmosMsg>>>(&self, msgs: T) -> StdResult<CosmosMsg> {
let msg = Cw1HandleMsg::Execute { msgs: msgs.into() };
Ok(WasmMsg::Execute {
contract_addr: self.addr(),
msg: to_binary(&msg)?,
send: vec![],
}
.into())
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct Cw1CanonicalContract(pub CanonicalAddr);
impl Cw1CanonicalContract {
pub fn human<A: Api>(&self, api: &A) -> StdResult<Cw1Contract> {
let human = api.human_address(&self.0)?;
Ok(Cw1Contract(human))
}
}