Skip to content

Commit

Permalink
Merge pull request #126 from CosmWasm/bound-option
Browse files Browse the repository at this point in the history
OwnedBound -> Option<Bound>
  • Loading branch information
ethanfrey authored Oct 16, 2020
2 parents 9908507 + 8b17c71 commit 508fbdc
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 125 deletions.
18 changes: 9 additions & 9 deletions contracts/cw3-fixed-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cw3::{
ProposalListResponse, ProposalResponse, Status, ThresholdResponse, Vote, VoteInfo,
VoteListResponse, VoteResponse, VoterListResponse, VoterResponse,
};
use cw_storage_plus::{Bound, OwnedBound};
use cw_storage_plus::Bound;

use crate::error::ContractError;
use crate::msg::{HandleMsg, InitMsg, QueryMsg};
Expand Down Expand Up @@ -332,9 +332,9 @@ fn list_proposals<S: Storage, A: Api, Q: Querier>(
limit: Option<u32>,
) -> StdResult<ProposalListResponse> {
let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
let start = OwnedBound::exclusive_int(start_after);
let start = start_after.map(Bound::exclusive_int);
let props: StdResult<Vec<_>> = PROPOSALS
.range(&deps.storage, start.bound(), Bound::None, Order::Ascending)
.range(&deps.storage, start, None, Order::Ascending)
.take(limit)
.map(|p| map_proposal(&env.block, p))
.collect();
Expand All @@ -349,9 +349,9 @@ fn reverse_proposals<S: Storage, A: Api, Q: Querier>(
limit: Option<u32>,
) -> StdResult<ProposalListResponse> {
let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
let end = OwnedBound::exclusive_int(start_before);
let end = start_before.map(Bound::exclusive_int);
let props: StdResult<Vec<_>> = PROPOSALS
.range(&deps.storage, Bound::None, end.bound(), Order::Descending)
.range(&deps.storage, None, end, Order::Descending)
.take(limit)
.map(|p| map_proposal(&env.block, p))
.collect();
Expand Down Expand Up @@ -394,12 +394,12 @@ fn list_votes<S: Storage, A: Api, Q: Querier>(
) -> StdResult<VoteListResponse> {
let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
let canon = maybe_canonical(deps.api, start_after)?;
let start = OwnedBound::exclusive(canon);
let start = canon.map(Bound::exclusive);

let api = &deps.api;
let votes: StdResult<Vec<_>> = BALLOTS
.prefix(proposal_id.into())
.range(&deps.storage, start.bound(), Bound::None, Order::Ascending)
.range(&deps.storage, start, None, Order::Ascending)
.take(limit)
.map(|item| {
let (key, ballot) = item?;
Expand Down Expand Up @@ -435,11 +435,11 @@ fn list_voters<S: Storage, A: Api, Q: Querier>(
) -> StdResult<VoterListResponse> {
let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
let canon = maybe_canonical(deps.api, start_after)?;
let start = OwnedBound::exclusive(canon);
let start = canon.map(Bound::exclusive);

let api = &deps.api;
let voters: StdResult<Vec<_>> = VOTERS
.range(&deps.storage, start.bound(), Bound::None, Order::Ascending)
.range(&deps.storage, start, None, Order::Ascending)
.take(limit)
.map(|item| {
let (key, weight) = item?;
Expand Down
6 changes: 3 additions & 3 deletions packages/storage-plus/src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{Binary, Order, StdError, StdResult, Storage, KV};

use crate::map::Map;
use crate::prefix::range_with_prefix;
use crate::{Bound, Endian};
use crate::Endian;

/// MARKER is stored in the multi-index as value, but we only look at the key (which is pk)
const MARKER: u32 = 1;
Expand Down Expand Up @@ -86,8 +86,8 @@ where
{
pub fn pks<'c>(&self, store: &'c S, idx: &[u8]) -> Box<dyn Iterator<Item = Vec<u8>> + 'c> {
let prefix = self.idx_map.prefix(idx);
let mapped = range_with_prefix(store, &prefix, Bound::None, Bound::None, Order::Ascending)
.map(|(k, _)| k);
let mapped =
range_with_prefix(store, &prefix, None, None, Order::Ascending).map(|(k, _)| k);
Box::new(mapped)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/storage-plus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pub use keys::{PkOwned, Prefixer, PrimaryKey, U128Key, U16Key, U32Key, U64Key};
pub use map::Map;
pub use path::Path;
#[cfg(feature = "iterator")]
pub use prefix::{Bound, OwnedBound, Prefix};
pub use prefix::{Bound, Prefix};
24 changes: 10 additions & 14 deletions packages/storage-plus/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ where
pub fn range<'c, S: Storage>(
&self,
store: &'c S,
min: Bound<'_>,
max: Bound<'_>,
min: Option<Bound>,
max: Option<Bound>,
order: cosmwasm_std::Order,
) -> Box<dyn Iterator<Item = StdResult<cosmwasm_std::KV<T>>> + 'c>
where
Expand Down Expand Up @@ -200,9 +200,7 @@ mod test {
PEOPLE.save(&mut store, b"jim", &data2).unwrap();

// let's try to iterate!
let all: StdResult<Vec<_>> = PEOPLE
.range(&store, Bound::None, Bound::None, Order::Ascending)
.collect();
let all: StdResult<Vec<_>> = PEOPLE.range(&store, None, None, Order::Ascending).collect();
let all = all.unwrap();
assert_eq!(2, all.len());
assert_eq!(
Expand Down Expand Up @@ -230,7 +228,7 @@ mod test {
// let's try to iterate!
let all: StdResult<Vec<_>> = ALLOWANCE
.prefix(b"owner")
.range(&store, Bound::None, Bound::None, Order::Ascending)
.range(&store, None, None, Order::Ascending)
.collect();
let all = all.unwrap();
assert_eq!(2, all.len());
Expand Down Expand Up @@ -384,9 +382,7 @@ mod test {
PEOPLE.save(&mut store, b"jim", &data2)?;

// iterate over them all
let all: StdResult<Vec<_>> = PEOPLE
.range(&store, Bound::None, Bound::None, Order::Ascending)
.collect();
let all: StdResult<Vec<_>> = PEOPLE.range(&store, None, None, Order::Ascending).collect();
assert_eq!(
all?,
vec![(b"jim".to_vec(), data2), (b"john".to_vec(), data.clone())]
Expand All @@ -396,8 +392,8 @@ mod test {
let all: StdResult<Vec<_>> = PEOPLE
.range(
&store,
Bound::Exclusive(b"jim"),
Bound::None,
Some(Bound::Exclusive(b"jim".to_vec())),
None,
Order::Ascending,
)
.collect();
Expand All @@ -411,7 +407,7 @@ mod test {
// get all under one key
let all: StdResult<Vec<_>> = ALLOWANCE
.prefix(b"owner")
.range(&store, Bound::None, Bound::None, Order::Ascending)
.range(&store, None, None, Order::Ascending)
.collect();
assert_eq!(
all?,
Expand All @@ -423,8 +419,8 @@ mod test {
.prefix(b"owner")
.range(
&store,
Bound::Exclusive(b"spender1"),
Bound::Inclusive(b"spender2"),
Some(Bound::Exclusive(b"spender1".to_vec())),
Some(Bound::Inclusive(b"spender2".to_vec())),
Order::Descending,
)
.collect();
Expand Down
Loading

0 comments on commit 508fbdc

Please sign in to comment.