Paged query for obtaining all delegatons
This commit is contained in:
@@ -22,9 +22,9 @@ use mixnet_contract_common::{
|
||||
ContractStateParams, Delegation, ExecuteMsg, Gateway, GatewayBond, GatewayBondResponse,
|
||||
GatewayOwnershipResponse, IdentityKey, Interval, LayerDistribution, MixNode, MixNodeBond,
|
||||
MixOwnershipResponse, MixnetContractVersion, MixnodeBondResponse,
|
||||
MixnodeRewardingStatusResponse, PagedDelegatorDelegationsResponse, PagedGatewayResponse,
|
||||
PagedMixDelegationsResponse, PagedMixnodeResponse, PagedRewardedSetResponse, QueryMsg,
|
||||
RewardedSetUpdateDetails,
|
||||
MixnodeRewardingStatusResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse,
|
||||
PagedGatewayResponse, PagedMixDelegationsResponse, PagedMixnodeResponse,
|
||||
PagedRewardedSetResponse, QueryMsg, RewardedSetUpdateDetails,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryInto;
|
||||
@@ -838,6 +838,22 @@ impl<C> NymdClient<C> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_all_delegations_paged(
|
||||
&self,
|
||||
start_after: Option<(IdentityKey, Vec<u8>, u64)>,
|
||||
) -> Result<PagedAllDelegationsResponse, NymdError>
|
||||
where
|
||||
C: CosmWasmClient + Sync,
|
||||
{
|
||||
let request = QueryMsg::GetAllDelegationValuesPaged {
|
||||
start_after,
|
||||
limit: None,
|
||||
};
|
||||
self.client
|
||||
.query_contract_smart(self.mixnet_contract_address(), &request)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Checks value of delegation of given client towards particular mixnode.
|
||||
pub async fn get_delegation_details(
|
||||
&self,
|
||||
|
||||
@@ -123,6 +123,10 @@ pub enum ExecuteMsg {
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum QueryMsg {
|
||||
GetAllDelegationValuesPaged {
|
||||
start_after: Option<(IdentityKey, Vec<u8>, u64)>,
|
||||
limit: Option<u32>,
|
||||
},
|
||||
GetBlacklistedNodes {},
|
||||
GetCurrentOperatorCost {},
|
||||
GetRewardingValidatorAddress {},
|
||||
|
||||
@@ -472,6 +472,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result<QueryResponse, C
|
||||
mix_identity,
|
||||
height,
|
||||
} => to_binary(&query_mixnode_at_height(deps, mix_identity, height)?),
|
||||
QueryMsg::GetAllDelegationValuesPaged { start_after, limit } => to_binary(
|
||||
&crate::delegations::queries::query_all_delegations_paged(deps, start_after, limit)?,
|
||||
),
|
||||
};
|
||||
|
||||
Ok(query_res?)
|
||||
|
||||
@@ -8,10 +8,7 @@ use cosmwasm_std::StdResult;
|
||||
use cosmwasm_std::{Api, Deps, Storage};
|
||||
use cw_storage_plus::{Bound, PrimaryKey};
|
||||
use mixnet_contract_common::mixnode::DelegationEvent;
|
||||
use mixnet_contract_common::{
|
||||
delegation, Delegation, IdentityKey, PagedDelegatorDelegationsResponse,
|
||||
PagedMixDelegationsResponse,
|
||||
};
|
||||
use mixnet_contract_common::{delegation, Delegation, IdentityKey, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, PagedMixDelegationsResponse};
|
||||
|
||||
pub(crate) fn query_pending_delegation_events(
|
||||
deps: Deps<'_>,
|
||||
@@ -80,6 +77,31 @@ pub fn query_all_delegation_keys(storage: &dyn Storage) -> Result<Vec<String>, C
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub(crate) fn query_all_delegations_paged(
|
||||
deps: Deps<'_>,
|
||||
start_after: Option<(IdentityKey, Vec<u8>, u64)>,
|
||||
limit: Option<u32>,
|
||||
) -> StdResult<PagedAllDelegationsResponse> {
|
||||
let limit = limit
|
||||
.unwrap_or(300)
|
||||
.min(500) as usize;
|
||||
|
||||
let start = start_after.map(Bound::exclusive);
|
||||
|
||||
let delegations = storage::delegations()
|
||||
.range(deps.storage, start, None, Order::Ascending)
|
||||
.take(limit)
|
||||
.map(|res| res.map(|item| item.1))
|
||||
.collect::<StdResult<Vec<_>>>()?;
|
||||
|
||||
let start_next_after = delegations.last().map(|del| del.storage_key());
|
||||
|
||||
Ok(PagedAllDelegationsResponse::new(
|
||||
delegations,
|
||||
start_next_after,
|
||||
))
|
||||
}
|
||||
|
||||
// This should only be exposed directly on the contract via nymd binary, not through the nymd clients
|
||||
pub fn debug_query_all_delegation_values(
|
||||
storage: &dyn Storage,
|
||||
|
||||
Reference in New Issue
Block a user