cw_proposal_sudo/
contract.rs1#[cfg(not(feature = "library"))]
2use cosmwasm_std::entry_point;
3use cosmwasm_std::{
4 to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
5 WasmMsg,
6};
7use cw2::set_contract_version;
8
9use crate::{
10 error::ContractError,
11 msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
12 state::{DAO, ROOT},
13};
14
15const CONTRACT_NAME: &str = "crates.io:cw-govmod-sudo";
16const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
17
18#[cfg_attr(not(feature = "library"), entry_point)]
19pub fn instantiate(
20 deps: DepsMut,
21 _env: Env,
22 info: MessageInfo,
23 msg: InstantiateMsg,
24) -> Result<Response, ContractError> {
25 set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
26
27 let root = deps.api.addr_validate(&msg.root)?;
28 ROOT.save(deps.storage, &root)?;
29 DAO.save(deps.storage, &info.sender)?;
30
31 Ok(Response::new()
32 .add_attribute("method", "instantiate")
33 .add_attribute("root", root))
34}
35
36#[cfg_attr(not(feature = "library"), entry_point)]
37pub fn execute(
38 deps: DepsMut,
39 _env: Env,
40 info: MessageInfo,
41 msg: ExecuteMsg,
42) -> Result<Response, ContractError> {
43 match msg {
44 ExecuteMsg::Execute { msgs } => execute_execute(deps.as_ref(), info.sender, msgs),
45 }
46}
47
48pub fn execute_execute(
49 deps: Deps,
50 sender: Addr,
51 msgs: Vec<CosmosMsg>,
52) -> Result<Response, ContractError> {
53 let root = ROOT.load(deps.storage)?;
54 let dao = DAO.load(deps.storage)?;
55
56 if sender != root {
57 return Err(ContractError::Unauthorized {});
58 }
59
60 let msg = WasmMsg::Execute {
61 contract_addr: dao.to_string(),
62 msg: to_binary(&cw_core_interface::ExecuteMsg::ExecuteProposalHook { msgs })?,
63 funds: vec![],
64 };
65
66 Ok(Response::default()
67 .add_attribute("action", "execute_execute")
68 .add_message(msg))
69}
70
71#[cfg_attr(not(feature = "library"), entry_point)]
72pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
73 match msg {
74 QueryMsg::Admin {} => query_admin(deps),
75 QueryMsg::Dao {} => query_dao(deps),
76 QueryMsg::Info {} => query_info(deps),
77 }
78}
79
80pub fn query_admin(deps: Deps) -> StdResult<Binary> {
81 to_binary(&ROOT.load(deps.storage)?)
82}
83
84pub fn query_dao(deps: Deps) -> StdResult<Binary> {
85 to_binary(&DAO.load(deps.storage)?)
86}
87
88pub fn query_info(deps: Deps) -> StdResult<Binary> {
89 let info = cw2::get_contract_version(deps.storage)?;
90 to_binary(&cw_core_interface::voting::InfoResponse { info })
91}