cw_orch_daemon/queriers/
authz.rs1use crate::{cosmos_modules, error::DaemonError, Daemon};
2use cosmrs::proto::cosmos::base::query::v1beta1::PageRequest;
3use cosmwasm_std::Addr;
4use cw_orch_core::environment::{Querier, QuerierGetter};
5use tokio::runtime::Handle;
6use tonic::transport::Channel;
7
8pub struct Authz {
11 pub channel: Channel,
12 pub rt_handle: Option<Handle>,
13}
14
15impl Authz {
16 pub fn new(daemon: &Daemon) -> Self {
17 Self {
18 channel: daemon.channel(),
19 rt_handle: Some(daemon.rt_handle.clone()),
20 }
21 }
22
23 pub fn new_async(channel: Channel) -> Self {
24 Self {
25 channel,
26 rt_handle: None,
27 }
28 }
29}
30
31impl Querier for Authz {
32 type Error = DaemonError;
33}
34
35impl QuerierGetter<Authz> for Daemon {
36 fn querier(&self) -> Authz {
37 Authz::new(self)
38 }
39}
40
41impl Authz {
42 pub async fn _grants(
44 &self,
45 granter: &Addr,
46 grantee: &Addr,
47 msg_type_url: String,
48 pagination: Option<PageRequest>,
49 ) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGrantsResponse, DaemonError> {
50 use cosmos_modules::authz::{query_client::QueryClient, QueryGrantsRequest};
51 let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
52 let grants = client
53 .grants(QueryGrantsRequest {
54 granter: granter.to_string(),
55 grantee: grantee.to_string(),
56 msg_type_url,
57 pagination,
58 })
59 .await?
60 .into_inner();
61 Ok(grants)
62 }
63
64 pub async fn _grantee_grants(
66 &self,
67 grantee: &Addr,
68 pagination: Option<PageRequest>,
69 ) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGranteeGrantsResponse, DaemonError>
70 {
71 use cosmos_modules::authz::{query_client::QueryClient, QueryGranteeGrantsRequest};
72 let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
73 let grants = client
74 .grantee_grants(QueryGranteeGrantsRequest {
75 grantee: grantee.to_string(),
76 pagination,
77 })
78 .await?
79 .into_inner();
80 Ok(grants)
81 }
82
83 pub async fn _granter_grants(
85 &self,
86 granter: &Addr,
87 pagination: Option<PageRequest>,
88 ) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGranterGrantsResponse, DaemonError>
89 {
90 use cosmos_modules::authz::{query_client::QueryClient, QueryGranterGrantsRequest};
91 let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
92 let grants = client
93 .granter_grants(QueryGranterGrantsRequest {
94 granter: granter.to_string(),
95 pagination,
96 })
97 .await?
98 .into_inner();
99 Ok(grants)
100 }
101}