diff --git a/sdk/src/queries/mod.rs b/sdk/src/queries/mod.rs index 354cd5b6d06..41c86876b1e 100644 --- a/sdk/src/queries/mod.rs +++ b/sdk/src/queries/mod.rs @@ -210,7 +210,7 @@ use std::fmt::{Debug, Display}; use tendermint_rpc::endpoint::{ abci_info, block, block_results, blockchain, commit, consensus_params, - consensus_state, health, net_info, status, + consensus_state, health, net_info, status, validators }; use tendermint_rpc::query::Query; use tendermint_rpc::{Error as RpcError, Order}; @@ -429,6 +429,97 @@ pub trait Client { self.perform(status::Request).await } + /// Cosmos Shim + + /// `/validators`: get validators at current block height unless specified + async fn validators( + &self, + height: Option, + prove: Option, + ) -> Result + { + let query_path = "/cosmos.staking.v1beta1.Query/Validators".to_string(); + let prove_value = prove.unwrap_or(false); + + self.abci_query( + Some(query_path), + Vec::new(), + height, + prove_value, + ) + .await + } + + /// `/balances`: get balances at current block height unless specified + async fn balances( + &self, + address: Option, + height: Option, + prove: Option, + ) -> Result { + let query_path = "/cosmos.bank.v1beta1.Query/AllBalances".to_string(); + let prove_value = prove.unwrap_or(false); + + self.abci_query( + Some(query_path), + address.unwrap_or_default().into_bytes(), + height, + prove_value, + ) + .await + } + + /// `/delegator_rewards`: get delegator rewards at current block height unless specified + async fn delegator_rewards( + &self, + delegator_address: Option, + validator_address: Option, + height: Option, + prove: Option, + ) -> Result { + let query_path = "/cosmos.distribution.v1beta1.Query/DelegationRewards".to_string(); + let prove_value = prove.unwrap_or(false); + + let mut query_data = Vec::new(); + if let Some(delegator) = delegator_address { + query_data.extend_from_slice(delegator.as_bytes()); + } + + if let Some(validator) = validator_address { + query_data.extend_from_slice(validator.as_bytes()); + } + + self.abci_query( + Some(query_path), + query_data, + height, + prove_value, + ).await + } + + /// `/validator_delegations`: get validator delegations at current block height unless specified + async fn validator_delegations( + &self, + validator_address: Option, + height: Option, + prove: Option, + ) -> Result { + let query_path = "/cosmos.staking.v1beta1.Query/ValidatorDelegations".to_string(); + let prove_value = prove.unwrap_or(false); + + let mut query_data = Vec::new(); + if let Some(validator) = validator_address { + query_data.extend_from_slice(validator.as_bytes()); + } + + self.abci_query( + Some(query_path), + query_data, + height, + prove_value, + ).await + } + /// Perform a request against the RPC endpoint async fn perform(&self, request: R) -> Result where