1use cosmwasm_std::{to_binary, Addr, Binary, Deps, StdResult};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::Role;
6
7#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
8#[serde(rename_all = "snake_case")]
9pub enum RbacQueryMsg {
10 HasRole {
11 address: Addr,
12 },
13 AllAccounts {
14 starts_after: Option<Addr>,
15 limit: Option<u32>,
16 },
17}
18
19#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
20pub struct HasRoleResponse {
21 pub has: bool,
22}
23
24#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
25pub struct AllAccountsResponse {
26 pub accounts: Vec<Addr>,
27}
28
29impl<'a> Role<'a> {
30 pub fn handle_query(&self, deps: Deps, msg: RbacQueryMsg) -> StdResult<Binary> {
31 match msg {
32 RbacQueryMsg::HasRole { address } => {
33 let has = self.has(deps.storage, &address)?;
34 Ok(to_binary(&HasRoleResponse { has })?)
35 }
36 RbacQueryMsg::AllAccounts {
37 starts_after,
38 limit,
39 } => {
40 let accounts = self.all_accounts(deps.storage, starts_after, limit)?;
41 Ok(to_binary(&AllAccountsResponse { accounts })?)
42 }
43 }
44 }
45}