cosmos_client/client/
slashing.rs1use crate::error::CosmosClient;
2use crate::error::CosmosClient::{ProstDecodeError, RpcError};
3use cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest;
4use cosmos_sdk_proto::cosmos::slashing::v1beta1::{
5 QueryParamsRequest, QueryParamsResponse, QuerySigningInfoRequest, QuerySigningInfoResponse,
6 QuerySigningInfosRequest, QuerySigningInfosResponse,
7};
8use prost::Message;
9use std::rc::Rc;
10use tendermint::abci::Code;
11use tendermint_rpc::{Client, HttpClient};
12
13pub struct Module {
14 rpc: Rc<HttpClient>,
15}
16
17impl Module {
18 pub fn new(rpc: Rc<HttpClient>) -> Self {
19 Module { rpc }
20 }
21
22 pub async fn params(&self) -> Result<QueryParamsResponse, CosmosClient> {
29 let query = QueryParamsRequest {};
30 let query = self
31 .rpc
32 .abci_query(
33 Some("/cosmos.slashing.v1beta1.Query/Params".to_string()),
34 query.encode_to_vec(),
35 None,
36 false,
37 )
38 .await?;
39
40 if query.code != Code::Ok {
41 return Err(RpcError(query.log));
42 }
43 QueryParamsResponse::decode(query.value.as_slice()).map_err(ProstDecodeError)
44 }
45
46 pub async fn signing_info(
53 &self,
54 cons_address: &str,
55 ) -> Result<QuerySigningInfoResponse, CosmosClient> {
56 let query = QuerySigningInfoRequest {
57 cons_address: cons_address.to_string(),
58 };
59 let query = self
60 .rpc
61 .abci_query(
62 Some("/cosmos.slashing.v1beta1.Query/SigningInfo".to_string()),
63 query.encode_to_vec(),
64 None,
65 false,
66 )
67 .await?;
68
69 if query.code != Code::Ok {
70 return Err(RpcError(query.log));
71 }
72 QuerySigningInfoResponse::decode(query.value.as_slice()).map_err(ProstDecodeError)
73 }
74
75 pub async fn signing_infos(
82 &self,
83 pagination: Option<PageRequest>,
84 ) -> Result<QuerySigningInfosResponse, CosmosClient> {
85 let query = QuerySigningInfosRequest { pagination };
86 let query = self
87 .rpc
88 .abci_query(
89 Some("/cosmos.slashing.v1beta1.Query/SigningInfos".to_string()),
90 query.encode_to_vec(),
91 None,
92 false,
93 )
94 .await?;
95
96 if query.code != Code::Ok {
97 return Err(RpcError(query.log));
98 }
99 QuerySigningInfosResponse::decode(query.value.as_slice()).map_err(ProstDecodeError)
100 }
101}