Skip to content

Commit

Permalink
Added pagination query for delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
baoskee committed Dec 28, 2022
1 parent b0e54d0 commit 5c1bc28
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/proposal/cwd-proposal-delegate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dao-pre-propose-base = { workspace = true }
dao-interface = { workspace = true }
dao-voting = { workspace = true }
cw-hooks = { workspace = true }
cw-paginate = { workspace = true }
dao-proposal-hooks = { workspace = true }
dao-vote-hooks = { workspace = true }
dao-pre-propose-multiple = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions contracts/proposal/cwd-proposal-delegate/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cosmwasm_std::{
to_binary, Binary, BlockInfo, Deps, DepsMut, Empty, Env, MessageInfo, OverflowError, Reply,
Response, StdError, StdResult, Storage, SubMsg, WasmMsg,
};
use cw_paginate::paginate_map_values;
use cw_utils::Expiration;
// use cw2::set_contract_version;

Expand Down Expand Up @@ -105,6 +106,16 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::Delegation { delegation_id } => {
Ok(to_binary(&query_delegation(deps, delegation_id)?)?)
}
QueryMsg::Delegations { start_after, limit } => {
let delegations = paginate_map_values(
deps,
&DELEGATIONS,
start_after,
limit,
cosmwasm_std::Order::Ascending,
)?;
Ok(to_binary(&delegations)?)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion contracts/proposal/cwd-proposal-delegate/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ pub enum ExecuteMsg {
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(DelegationResponse)]
#[returns(Delegation)]
Delegation { delegation_id: u64 },
#[returns(Vec<Delegation>)]
Delegations {
start_after: Option<u64>,
limit: Option<u32>,
},
}

pub type DelegationResponse = Delegation;

0 comments on commit 5c1bc28

Please sign in to comment.