Skip to content

Commit

Permalink
Filter out non-whitelist-props in query_top_n_proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Apr 22, 2024
1 parent 5630918 commit 84b3512
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion contracts/atom_wars/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,26 @@ pub fn query_top_n_proposals(
return Err(StdError::generic_err("Tranche does not exist"));
}

// Iterate through PROPS_BY_SCORE to find the top num props
// load the whitelist
let whitelist = WHITELIST.load(deps.storage)?;

// Iterate through PROPS_BY_SCORE to find the top num props, while ignoring
// any props that are not on the whitelist
let top_prop_ids: Vec<u64> = PROPS_BY_SCORE
.sub_prefix((round_id, tranche_id))
.range(deps.storage, None, None, Order::Descending)
// filter out any props that are not on the whitelist
.filter(|x| match x {
Ok((_, prop_id)) => {
let prop = PROPOSAL_MAP.load(deps.storage, (round_id, tranche_id, prop_id)).unwrap();
if whitelist.contains(&prop.covenant_params) {
true
} else {
false
}
}
Err(e) => false,
})
.take(num)
.map(|x| match x {
Ok((_, prop_id)) => prop_id,
Expand Down

0 comments on commit 84b3512

Please sign in to comment.