use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use thiserror::Error; use cosmwasm_rbac::{RbacError, RbacExecuteMsg, RbacQueryMsg, Role}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct InstantiateMsg {} #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ExecuteMsg { Admin(RbacExecuteMsg), } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { Admin(RbacQueryMsg), } #[derive(Error, Debug, PartialEq)] pub enum ContractError { #[error("{0}")] Rbac(#[from] RbacError), } /// here we define admin role const ADMINS: Role = Role::new("admins"); #[entry_point] pub fn instantiate( deps: DepsMut, _env: Env, info: MessageInfo, _msg: InstantiateMsg, ) -> Result { ADMINS.grant(deps.storage, info.sender.clone())?; Ok(Response::new() .add_attribute("method", "instantiate") .add_attribute("owner", info.sender)) } #[entry_point] pub fn execute( deps: DepsMut, _env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { ExecuteMsg::Admin(rbac_msg) => { ADMINS.check(deps.storage, &info.sender)?; Ok(ADMINS.handle_execute(deps, info, rbac_msg)?) } } } #[entry_point] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::Admin(rbac_msg) => Ok(ADMINS.handle_query(deps, rbac_msg)?), } } fn main() {}