tg4_group/
helpers.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::ops::Deref;
4
5use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg};
6use tg4::{Member, Tg4Contract};
7
8use crate::msg::ExecuteMsg;
9
10/// Tg4GroupContract is a wrapper around Tg4Contract that provides a lot of helpers
11/// for working with tg4-group contracts.
12///
13/// It extends Tg4Contract to add the extra calls from tg4-group.
14#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
15pub struct Tg4GroupContract(pub Tg4Contract);
16
17impl Deref for Tg4GroupContract {
18    type Target = Tg4Contract;
19
20    fn deref(&self) -> &Self::Target {
21        &self.0
22    }
23}
24
25impl Tg4GroupContract {
26    pub fn new(addr: Addr) -> Self {
27        Tg4GroupContract(Tg4Contract(addr))
28    }
29
30    fn encode_msg(&self, msg: ExecuteMsg) -> StdResult<CosmosMsg> {
31        Ok(WasmMsg::Execute {
32            contract_addr: self.addr().into(),
33            msg: to_binary(&msg)?,
34            funds: vec![],
35        }
36        .into())
37    }
38
39    pub fn update_members(&self, remove: Vec<String>, add: Vec<Member>) -> StdResult<CosmosMsg> {
40        let msg = ExecuteMsg::UpdateMembers { remove, add };
41        self.encode_msg(msg)
42    }
43}