use crate::{cosmos_modules, error::DaemonError, Daemon};
use cosmrs::proto::cosmos::base::query::v1beta1::PageRequest;
use cw_orch_core::environment::{Querier, QuerierGetter};
use tokio::runtime::Handle;
use tonic::transport::Channel;
pub struct Authz {
pub channel: Channel,
pub rt_handle: Option<Handle>,
}
impl Authz {
pub fn new(daemon: &Daemon) -> Self {
Self {
channel: daemon.channel(),
rt_handle: Some(daemon.rt_handle.clone()),
}
}
pub fn new_async(channel: Channel) -> Self {
Self {
channel,
rt_handle: None,
}
}
}
impl Querier for Authz {
type Error = DaemonError;
}
impl QuerierGetter<Authz> for Daemon {
fn querier(&self) -> Authz {
Authz::new(self)
}
}
impl Authz {
pub async fn _grants(
&self,
granter: String,
grantee: String,
msg_type_url: String,
pagination: Option<PageRequest>,
) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGrantsResponse, DaemonError> {
use cosmos_modules::authz::{query_client::QueryClient, QueryGrantsRequest};
let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
let grants = client
.grants(QueryGrantsRequest {
granter,
grantee,
msg_type_url,
pagination,
})
.await?
.into_inner();
Ok(grants)
}
pub async fn _grantee_grants(
&self,
grantee: String,
pagination: Option<PageRequest>,
) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGranteeGrantsResponse, DaemonError>
{
use cosmos_modules::authz::{query_client::QueryClient, QueryGranteeGrantsRequest};
let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
let grants = client
.grantee_grants(QueryGranteeGrantsRequest {
grantee,
pagination,
})
.await?
.into_inner();
Ok(grants)
}
pub async fn _granter_grants(
&self,
granter: String,
pagination: Option<PageRequest>,
) -> Result<cosmrs::proto::cosmos::authz::v1beta1::QueryGranterGrantsResponse, DaemonError>
{
use cosmos_modules::authz::{query_client::QueryClient, QueryGranterGrantsRequest};
let mut client: QueryClient<Channel> = QueryClient::new(self.channel.clone());
let grants = client
.granter_grants(QueryGranterGrantsRequest {
granter,
pagination,
})
.await?
.into_inner();
Ok(grants)
}
}