From d012560ea1278ac3f203b5f7623c72be80f43060 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 10 Dec 2021 23:06:19 +0100 Subject: [PATCH 01/47] Introduce range_raw over Prefix --- packages/storage-plus/src/indexes/multi.rs | 18 ++++--- packages/storage-plus/src/indexes/unique.rs | 60 ++++++++++++++------- packages/storage-plus/src/prefix.rs | 43 +++++++++++---- 3 files changed, 87 insertions(+), 34 deletions(-) diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 4b8bd5c8e..1ee2373d2 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -144,29 +144,32 @@ where IK: PrimaryKey<'a> + Prefixer<'a>, { pub fn prefix(&self, p: IK) -> Prefix, T> { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), self.pk_namespace, deserialize_multi_v, + deserialize_multi_v, ) } pub fn sub_prefix(&self, p: IK::Prefix) -> Prefix, T> { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), self.pk_namespace, deserialize_multi_v, + deserialize_multi_v, ) } fn no_prefix(&self) -> Prefix, T> { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &[], self.pk_namespace, deserialize_multi_v, + deserialize_multi_v, ) } @@ -257,20 +260,22 @@ where IK: PrimaryKey<'a> + Prefixer<'a>, { pub fn prefix_de(&self, p: IK) -> Prefix { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), self.pk_namespace, deserialize_multi_kv::, + deserialize_multi_v, ) } pub fn sub_prefix_de(&self, p: IK::Prefix) -> Prefix { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), self.pk_namespace, deserialize_multi_kv::, + deserialize_multi_v, ) } } @@ -336,11 +341,12 @@ where } fn no_prefix_de(&self) -> Prefix { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( self.idx_namespace, &[], self.pk_namespace, deserialize_multi_kv::, + deserialize_multi_v, ) } } diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 13d033475..922f3f647 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -113,21 +113,33 @@ where } pub fn prefix(&self, p: IK::Prefix) -> Prefix, T> { - Prefix::with_deserialization_function(self.idx_namespace, &p.prefix(), &[], |_, _, kv| { - deserialize_unique_v(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &p.prefix(), + &[], + |_, _, kv| deserialize_unique_v(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } pub fn sub_prefix(&self, p: IK::SubPrefix) -> Prefix, T> { - Prefix::with_deserialization_function(self.idx_namespace, &p.prefix(), &[], |_, _, kv| { - deserialize_unique_v(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &p.prefix(), + &[], + |_, _, kv| deserialize_unique_v(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } fn no_prefix(&self) -> Prefix, T> { - Prefix::with_deserialization_function(self.idx_namespace, &[], &[], |_, _, kv| { - deserialize_unique_v(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &[], + &[], + |_, _, kv| deserialize_unique_v(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } /// returns all items that match this secondary index, always by pk Ascending @@ -233,20 +245,32 @@ where } pub fn prefix_de(&self, p: IK::Prefix) -> Prefix { - Prefix::with_deserialization_function(self.idx_namespace, &p.prefix(), &[], |_, _, kv| { - deserialize_unique_kv::(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &p.prefix(), + &[], + |_, _, kv| deserialize_unique_kv::(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } pub fn sub_prefix_de(&self, p: IK::SubPrefix) -> Prefix { - Prefix::with_deserialization_function(self.idx_namespace, &p.prefix(), &[], |_, _, kv| { - deserialize_unique_kv::(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &p.prefix(), + &[], + |_, _, kv| deserialize_unique_kv::(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } fn no_prefix_de(&self) -> Prefix { - Prefix::with_deserialization_function(self.idx_namespace, &[], &[], |_, _, kv| { - deserialize_unique_kv::(kv) - }) + Prefix::with_deserialization_functions( + self.idx_namespace, + &[], + &[], + |_, _, kv| deserialize_unique_kv::(kv), + |_, _, kv| deserialize_unique_v(kv), + ) } } diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index 808d62638..4356830c2 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -67,10 +67,11 @@ impl<'a, K: Prefixer<'a>> PrefixBound<'a, K> { } } +type DeserializeVFn = fn(&dyn Storage, &[u8], Record) -> StdResult>; + type DeserializeKvFn = fn(&dyn Storage, &[u8], Record) -> StdResult<(::Output, T)>; -#[allow(dead_code)] pub fn default_deserializer_v( _: &dyn Storage, _: &[u8], @@ -98,7 +99,8 @@ where // see https://doc.rust-lang.org/std/marker/struct.PhantomData.html#unused-type-parameters for why this is needed data: PhantomData, pk_name: Vec, - de_fn: DeserializeKvFn, + de_fn_kv: DeserializeKvFn, + de_fn_v: DeserializeVFn, } impl Deref for Prefix @@ -119,29 +121,49 @@ where T: Serialize + DeserializeOwned, { pub fn new(top_name: &[u8], sub_names: &[Key]) -> Self { - Prefix::with_deserialization_function( + Prefix::with_deserialization_functions( top_name, sub_names, &[], default_deserializer_kv::, + default_deserializer_v, ) } - pub fn with_deserialization_function( + pub fn with_deserialization_functions( top_name: &[u8], sub_names: &[Key], pk_name: &[u8], - de_fn: DeserializeKvFn, + de_fn_kv: DeserializeKvFn, + de_fn_v: DeserializeVFn, ) -> Self { let storage_prefix = nested_namespaces_with_key(&[top_name], sub_names, b""); Prefix { storage_prefix, data: PhantomData, pk_name: pk_name.to_vec(), - de_fn, + de_fn_kv, + de_fn_v, } } + pub fn range_raw<'a>( + &self, + store: &'a dyn Storage, + min: Option, + max: Option, + order: Order, + ) -> Box>> + 'a> + where + T: 'a, + { + let de_fn = self.de_fn_v; + let pk_name = self.pk_name.clone(); + let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) + .map(move |kv| (de_fn)(store, &*pk_name, kv)); + Box::new(mapped) + } + pub fn range<'a>( &self, store: &'a dyn Storage, @@ -153,7 +175,7 @@ where T: 'a, K::Output: 'a, { - let de_fn = self.de_fn; + let de_fn = self.de_fn_kv; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) .map(move |kv| (de_fn)(store, &*pk_name, kv)); @@ -183,7 +205,7 @@ where T: 'a, K::Output: 'static, { - let de_fn = self.de_fn; + let de_fn = self.de_fn_kv; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) .map(move |kv| (de_fn)(store, &*pk_name, kv)); @@ -201,7 +223,7 @@ where T: 'a, K::Output: 'static, { - let de_fn = self.de_fn; + let de_fn = self.de_fn_kv; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) .map(move |kv| (de_fn)(store, &*pk_name, kv).map(|(k, _)| Ok(k))) @@ -326,7 +348,8 @@ mod test { storage_prefix: b"foo".to_vec(), data: PhantomData::, pk_name: vec![], - de_fn: |_, _, kv| deserialize_kv::, u64>(kv), + de_fn_kv: |_, _, kv| deserialize_kv::, u64>(kv), + de_fn_v: |_, _, kv| deserialize_v(kv), }; // set some data, we care about "foo" prefix From c7d1723f5c3357221b5f9725538898a4a60d1a84 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 10 Dec 2021 23:18:12 +0100 Subject: [PATCH 02/47] Replace prefix() + range() by prefix_de() + range_raw() Remove prefix() --- contracts/cw1155-base/src/contract.rs | 8 +++--- contracts/cw20-base/src/enumerable.rs | 4 +-- contracts/cw20-ics20/src/contract.rs | 4 +-- contracts/cw3-fixed-multisig/src/contract.rs | 4 +-- contracts/cw3-flex-multisig/src/contract.rs | 4 +-- packages/storage-plus/src/map.rs | 27 ++++++++------------ packages/storage-plus/src/snapshot/map.rs | 4 --- packages/storage-plus/src/snapshot/mod.rs | 8 +++--- 8 files changed, 27 insertions(+), 36 deletions(-) diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index d52940a7a..4c2296464 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -497,8 +497,8 @@ fn query_all_approvals( let start = start_after.map(|addr| Bound::exclusive(addr.as_ref())); let operators = APPROVES - .prefix(&owner) - .range(deps.storage, start, None, Order::Ascending) + .prefix_de(&owner) + .range_raw(deps.storage, start, None, Order::Ascending) .filter(|r| include_expired || r.is_err() || !r.as_ref().unwrap().1.is_expired(&env.block)) .take(limit) .map(parse_approval) @@ -516,8 +516,8 @@ fn query_tokens( let start = start_after.map(Bound::exclusive); let tokens = BALANCES - .prefix(&owner) - .range(deps.storage, start, None, Order::Ascending) + .prefix_de(&owner) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| item.map(|(k, _)| String::from_utf8(k).unwrap())) .collect::>()?; diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index 2f97be5fa..1bdb46a94 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -19,8 +19,8 @@ pub fn query_all_allowances( let start = start_after.map(Bound::exclusive); let allowances: StdResult> = ALLOWANCES - .prefix(&owner_addr) - .range(deps.storage, start, None, Order::Ascending) + .prefix_de(&owner_addr) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (k, v) = item?; diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index a8834eb96..ca959f473 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -165,8 +165,8 @@ pub fn query_channel(deps: Deps, id: String) -> StdResult { let info = CHANNEL_INFO.load(deps.storage, &id)?; // this returns Vec<(outstanding, total)> let state: StdResult> = CHANNEL_STATE - .prefix(&id) - .range(deps.storage, None, None, Order::Ascending) + .prefix_de(&id) + .range_raw(deps.storage, None, None, Order::Ascending) .map(|r| { let (k, v) = r?; let denom = String::from_utf8(k)?; diff --git a/contracts/cw3-fixed-multisig/src/contract.rs b/contracts/cw3-fixed-multisig/src/contract.rs index 287946334..ce739f702 100644 --- a/contracts/cw3-fixed-multisig/src/contract.rs +++ b/contracts/cw3-fixed-multisig/src/contract.rs @@ -386,8 +386,8 @@ fn list_votes( let start = start_after.map(Bound::exclusive); let votes: StdResult> = BALLOTS - .prefix(proposal_id) - .range(deps.storage, start, None, Order::Ascending) + .prefix_de(proposal_id) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (key, ballot) = item?; diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index eafc2b221..c1b3f695b 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -383,8 +383,8 @@ fn list_votes( let start = addr.map(|addr| Bound::exclusive(addr.as_ref())); let votes: StdResult> = BALLOTS - .prefix(proposal_id) - .range(deps.storage, start, None, Order::Ascending) + .prefix_de(proposal_id) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (voter, ballot) = item?; diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 2b623e82f..9058e8037 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -49,11 +49,6 @@ where ) } - #[cfg(feature = "iterator")] - pub fn prefix(&self, p: K::Prefix) -> Prefix, T> { - Prefix::new(self.namespace, &p.prefix()) - } - #[cfg(feature = "iterator")] pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { Prefix::new(self.namespace, &p.prefix()) @@ -611,8 +606,8 @@ mod test { // let's try to iterate over a prefix let all: StdResult> = ALLOWANCE - .prefix(b"owner") - .range(&store, None, None, Order::Ascending) + .prefix_de(b"owner") + .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -713,8 +708,8 @@ mod test { // let's iterate over a prefix let all: StdResult> = TRIPLE - .prefix((b"owner", 9)) - .range(&store, None, None, Order::Ascending) + .prefix_de((b"owner", 9)) + .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -981,8 +976,8 @@ mod test { // get all under one key let all: StdResult> = ALLOWANCE - .prefix(b"owner") - .range(&store, None, None, Order::Ascending) + .prefix_de(b"owner") + .range_raw(&store, None, None, Order::Ascending) .collect(); assert_eq!( all?, @@ -991,8 +986,8 @@ mod test { // Or ranges between two items (even reverse) let all: StdResult> = ALLOWANCE - .prefix(b"owner") - .range( + .prefix_de(b"owner") + .range_raw( &store, Some(Bound::Exclusive(b"spender1".to_vec())), Some(Bound::Inclusive(b"spender2".to_vec())), @@ -1021,8 +1016,8 @@ mod test { // typical range under one prefix as a control let fives = AGES - .prefix(5) - .range(&store, None, None, Order::Ascending) + .prefix_de(5) + .range_raw(&store, None, None, Order::Ascending) .collect::>>() .unwrap(); assert_eq!(fives.len(), 2); @@ -1119,7 +1114,7 @@ mod test { ); let keys: Vec<_> = AGES - .no_prefix() + .no_prefix_de() .keys_de(&store, None, None, Order::Ascending) .collect(); println!("keys: {:?}", keys); diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index fb5a4c864..87cfc703b 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -69,10 +69,6 @@ where self.primary.key(k) } - pub fn prefix(&self, p: K::Prefix) -> Prefix, T> { - self.primary.prefix(p) - } - pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { self.primary.sub_prefix(p) } diff --git a/packages/storage-plus/src/snapshot/mod.rs b/packages/storage-plus/src/snapshot/mod.rs index d0418ce2c..e8a587d1f 100644 --- a/packages/storage-plus/src/snapshot/mod.rs +++ b/packages/storage-plus/src/snapshot/mod.rs @@ -87,8 +87,8 @@ where let start = Bound::inclusive(height); let first = self .changelog - .prefix(k.clone()) - .range(store, Some(start), None, Order::Ascending) + .prefix_de(k.clone()) + .range_raw(store, Some(start), None, Order::Ascending) .next() .transpose()?; if first.is_none() { @@ -146,8 +146,8 @@ where let start = Bound::inclusive_int(height); let first = self .changelog - .prefix(key) - .range(store, Some(start), None, Order::Ascending) + .prefix_de(key) + .range_raw(store, Some(start), None, Order::Ascending) .next(); if let Some(r) = first { From 7069f39b9b4459e13f51752e5e5a872ba25899a6 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 10 Dec 2021 23:22:37 +0100 Subject: [PATCH 03/47] Replace sub_prefix() + range() by sub_prefix_de() + range_raw() Remove sub_prefix() --- packages/storage-plus/src/map.rs | 9 ++------- packages/storage-plus/src/snapshot/map.rs | 4 ---- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 9058e8037..1e7471074 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -49,11 +49,6 @@ where ) } - #[cfg(feature = "iterator")] - pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { - Prefix::new(self.namespace, &p.prefix()) - } - #[cfg(feature = "iterator")] pub(crate) fn no_prefix(&self) -> Prefix, T> { Prefix::new(self.namespace, &[]) @@ -723,8 +718,8 @@ mod test { // let's iterate over a sub prefix let all: StdResult> = TRIPLE - .sub_prefix(b"owner") - .range(&store, None, None, Order::Ascending) + .sub_prefix_de(b"owner") + .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(3, all.len()); diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 87cfc703b..9086083a6 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -69,10 +69,6 @@ where self.primary.key(k) } - pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { - self.primary.sub_prefix(p) - } - fn no_prefix(&self) -> Prefix, T> { self.primary.no_prefix() } From 376cc58fad564121b90e996da92b4e9559069e6d Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 10 Dec 2021 23:40:27 +0100 Subject: [PATCH 04/47] Replace no_prefix() + range() by no_prefix() + range_raw() --- packages/storage-plus/src/map.rs | 2 +- packages/storage-plus/src/snapshot/map.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 1e7471074..33526fd7c 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -164,7 +164,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } pub fn keys<'c>( diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 9086083a6..24b03ccc0 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -174,7 +174,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } } From e047a906ce2f873c8a3bae5b15cb4c071c3ae5ba Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Fri, 10 Dec 2021 23:45:58 +0100 Subject: [PATCH 05/47] Rename keys to keys_raw --- contracts/cw20-atomic-swap/src/state.rs | 2 +- contracts/cw20-base/src/enumerable.rs | 2 +- contracts/cw20-escrow/src/state.rs | 2 +- packages/storage-plus/src/indexed_map.rs | 2 +- packages/storage-plus/src/indexed_snapshot.rs | 2 +- packages/storage-plus/src/indexes/multi.rs | 6 +++--- packages/storage-plus/src/indexes/unique.rs | 2 +- packages/storage-plus/src/map.rs | 7 +++---- packages/storage-plus/src/prefix.rs | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/contracts/cw20-atomic-swap/src/state.rs b/contracts/cw20-atomic-swap/src/state.rs index ac67aa6b0..7df449e9d 100644 --- a/contracts/cw20-atomic-swap/src/state.rs +++ b/contracts/cw20-atomic-swap/src/state.rs @@ -32,7 +32,7 @@ pub fn all_swap_ids( limit: usize, ) -> StdResult> { SWAPS - .keys(storage, start, None, Order::Ascending) + .keys_raw(storage, start, None, Order::Ascending) .take(limit) .map(|k| String::from_utf8(k).map_err(|_| StdError::invalid_utf8("Parsing swap id"))) .collect() diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index 1bdb46a94..319097ac3 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -45,7 +45,7 @@ pub fn query_all_accounts( let start = start_after.map(Bound::exclusive); let accounts: Result, _> = BALANCES - .keys(deps.storage, start, None, Order::Ascending) + .keys_raw(deps.storage, start, None, Order::Ascending) .map(String::from_utf8) .take(limit) .collect(); diff --git a/contracts/cw20-escrow/src/state.rs b/contracts/cw20-escrow/src/state.rs index 4539f826c..c09dcd3e2 100644 --- a/contracts/cw20-escrow/src/state.rs +++ b/contracts/cw20-escrow/src/state.rs @@ -95,7 +95,7 @@ pub const ESCROWS: Map<&str, Escrow> = Map::new("escrow"); /// This returns the list of ids for all registered escrows pub fn all_escrow_ids(storage: &dyn Storage) -> StdResult> { ESCROWS - .keys(storage, None, None, Order::Ascending) + .keys_raw(storage, None, None, Order::Ascending) .map(|k| String::from_utf8(k).map_err(|_| StdError::invalid_utf8("parsing escrow key"))) .collect() } diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 580182a31..aa6e0d8c7 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -828,7 +828,7 @@ mod test { map.idx .name .prefix(name.to_string()) - .keys(store, None, None, Order::Ascending) + .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 8b4470927..dc99fa3f5 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -819,7 +819,7 @@ mod test { map.idx .name .prefix(name.as_bytes().to_vec()) - .keys(store, None, None, Order::Ascending) + .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 1ee2373d2..44e99c819 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -180,14 +180,14 @@ where #[cfg(test)] pub fn count(&self, store: &dyn Storage, p: IK) -> usize { let prefix = self.prefix(p); - prefix.keys(store, None, None, Order::Ascending).count() + prefix.keys_raw(store, None, None, Order::Ascending).count() } #[cfg(test)] pub fn all_pks(&self, store: &dyn Storage, p: IK) -> Vec> { let prefix = self.prefix(p); prefix - .keys(store, None, None, Order::Ascending) + .keys_raw(store, None, None, Order::Ascending) .collect::>>() } @@ -226,7 +226,7 @@ where max: Option, order: Order, ) -> Box> + 'c> { - self.no_prefix().keys(store, min, max, order) + self.no_prefix().keys_raw(store, min, max, order) } /// While `range` over a `prefix` fixes the prefix to one element and iterates over the diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 922f3f647..7b02ea7c2 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -180,7 +180,7 @@ where max: Option, order: Order, ) -> Box> + 'c> { - self.no_prefix().keys(store, min, max, order) + self.no_prefix().keys_raw(store, min, max, order) } } diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 33526fd7c..568684834 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -167,7 +167,7 @@ where self.no_prefix().range_raw(store, min, max, order) } - pub fn keys<'c>( + pub fn keys_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -177,7 +177,7 @@ where where T: 'c, { - self.no_prefix().keys(store, min, max, order) + self.no_prefix().keys_raw(store, min, max, order) } } @@ -1019,8 +1019,7 @@ mod test { assert_eq!(fives, vec![(vec![7, 8, 9], 789), (vec![9, 8, 7], 987)]); let keys: Vec<_> = AGES - .no_prefix() - .keys(&store, None, None, Order::Ascending) + .keys_raw(&store, None, None, Order::Ascending) .collect(); println!("keys: {:?}", keys); diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index 4356830c2..8a4335b25 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -182,7 +182,7 @@ where Box::new(mapped) } - pub fn keys<'a>( + pub fn keys_raw<'a>( &self, store: &'a dyn Storage, min: Option, From d0fd20e283c7e5dd98d619f4c6a99910df8eb241 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 07:33:51 +0100 Subject: [PATCH 06/47] Rename range to range_raw --- contracts/cw1-subkeys/src/contract.rs | 4 ++-- contracts/cw1155-base/src/contract.rs | 2 +- contracts/cw20-ics20/src/contract.rs | 2 +- contracts/cw3-fixed-multisig/src/contract.rs | 6 +++--- contracts/cw3-flex-multisig/src/contract.rs | 4 ++-- packages/controllers/src/claim.rs | 2 +- packages/multi-test/src/wasm.rs | 2 +- packages/storage-plus/src/map.rs | 22 +++++++++++++------- packages/storage-plus/src/snapshot/mod.rs | 2 +- packages/utils/src/pagination.rs | 4 ++-- 10 files changed, 28 insertions(+), 22 deletions(-) diff --git a/contracts/cw1-subkeys/src/contract.rs b/contracts/cw1-subkeys/src/contract.rs index f20a65ec6..84304be68 100644 --- a/contracts/cw1-subkeys/src/contract.rs +++ b/contracts/cw1-subkeys/src/contract.rs @@ -410,7 +410,7 @@ pub fn query_all_allowances( let start = start_after.map(Bound::exclusive); let res: StdResult> = ALLOWANCES - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .filter(|item| { if let Ok((_, allow)) = item { !allow.expires.is_expired(&env.block) @@ -442,7 +442,7 @@ pub fn query_all_permissions( let start = start_after.map(Bound::exclusive); let res: StdResult> = PERMISSIONS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { item.and_then(|(k, perm)| { diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index 4c2296464..75c6ebbdf 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -532,7 +532,7 @@ fn query_all_tokens( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); let tokens = TOKENS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| item.map(|(k, _)| String::from_utf8(k).unwrap())) .collect::>()?; diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index ca959f473..d3c3f3f0b 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -152,7 +152,7 @@ fn query_port(deps: Deps) -> StdResult { fn query_list(deps: Deps) -> StdResult { let channels: StdResult> = CHANNEL_INFO - .range(deps.storage, None, None, Order::Ascending) + .range_raw(deps.storage, None, None, Order::Ascending) .map(|r| r.map(|(_, v)| v)) .collect(); Ok(ListChannelsResponse { diff --git a/contracts/cw3-fixed-multisig/src/contract.rs b/contracts/cw3-fixed-multisig/src/contract.rs index ce739f702..f99882a1d 100644 --- a/contracts/cw3-fixed-multisig/src/contract.rs +++ b/contracts/cw3-fixed-multisig/src/contract.rs @@ -316,7 +316,7 @@ fn list_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive_int); let props: StdResult> = PROPOSALS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|p| map_proposal(&env.block, &threshold, p)) .collect(); @@ -339,7 +339,7 @@ fn reverse_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let end = start_before.map(Bound::exclusive_int); let props: StdResult> = PROPOSALS - .range(deps.storage, None, end, Order::Descending) + .range_raw(deps.storage, None, end, Order::Descending) .take(limit) .map(|p| map_proposal(&env.block, &threshold, p)) .collect(); @@ -417,7 +417,7 @@ fn list_voters( let start = start_after.map(Bound::exclusive); let voters: StdResult> = VOTERS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (key, weight) = item?; diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index c1b3f695b..b508331b4 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -318,7 +318,7 @@ fn list_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive_int); let props: StdResult> = PROPOSALS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|p| map_proposal(&env.block, p)) .collect(); @@ -335,7 +335,7 @@ fn reverse_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let end = start_before.map(Bound::exclusive_int); let props: StdResult> = PROPOSALS - .range(deps.storage, None, end, Order::Descending) + .range_raw(deps.storage, None, end, Order::Descending) .take(limit) .map(|p| map_proposal(&env.block, p)) .collect(); diff --git a/packages/controllers/src/claim.rs b/packages/controllers/src/claim.rs index 693fd2e7e..b4d1b502c 100644 --- a/packages/controllers/src/claim.rs +++ b/packages/controllers/src/claim.rs @@ -118,7 +118,7 @@ mod test { assert_eq!( claims .0 - .range(&deps.storage, None, None, Order::Ascending) + .range_raw(&deps.storage, None, None, Order::Ascending) .collect::>>() .unwrap() .len(), diff --git a/packages/multi-test/src/wasm.rs b/packages/multi-test/src/wasm.rs index 9b98bf509..1e1ef5872 100644 --- a/packages/multi-test/src/wasm.rs +++ b/packages/multi-test/src/wasm.rs @@ -791,7 +791,7 @@ where fn next_address(&self, storage: &dyn Storage) -> Addr { // FIXME: quite inefficient if we actually had 100s of contracts let count = CONTRACTS - .range(storage, None, None, Order::Ascending) + .range_raw(storage, None, None, Order::Ascending) .count(); // we make this longer so it is not rejected by tests Addr::unchecked(format!("Contract #{}", count.to_string())) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 568684834..5917a09c7 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -154,7 +154,7 @@ where Box::new(mapped) } - pub fn range<'c>( + pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -412,7 +412,9 @@ mod test { PEOPLE.save(&mut store, b"jim", &data2).unwrap(); // let's try to iterate! - let all: StdResult> = PEOPLE.range(&store, None, None, Order::Ascending).collect(); + let all: StdResult> = PEOPLE + .range_raw(&store, None, None, Order::Ascending) + .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); assert_eq!( @@ -425,7 +427,7 @@ mod test { // let's try to iterate over a range let all: StdResult> = PEOPLE - .range( + .range_raw( &store, Some(Bound::Inclusive(b"j".to_vec())), None, @@ -441,7 +443,7 @@ mod test { // let's try to iterate over a more restrictive range let all: StdResult> = PEOPLE - .range( + .range_raw( &store, Some(Bound::Inclusive(b"jo".to_vec())), None, @@ -586,7 +588,7 @@ mod test { // let's try to iterate! let all: StdResult> = ALLOWANCE - .range(&store, None, None, Order::Ascending) + .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(3, all.len()); @@ -676,7 +678,9 @@ mod test { .unwrap(); // let's try to iterate! - let all: StdResult> = TRIPLE.range(&store, None, None, Order::Ascending).collect(); + let all: StdResult> = TRIPLE + .range_raw(&store, None, None, Order::Ascending) + .collect(); let all = all.unwrap(); assert_eq!(4, all.len()); assert_eq!( @@ -947,7 +951,9 @@ mod test { PEOPLE.save(&mut store, b"jim", &data2)?; // iterate over them all - let all: StdResult> = PEOPLE.range(&store, None, None, Order::Ascending).collect(); + let all: StdResult> = PEOPLE + .range_raw(&store, None, None, Order::Ascending) + .collect(); assert_eq!( all?, vec![(b"jim".to_vec(), data2), (b"john".to_vec(), data.clone())] @@ -955,7 +961,7 @@ mod test { // or just show what is after jim let all: StdResult> = PEOPLE - .range( + .range_raw( &store, Some(Bound::Exclusive(b"jim".to_vec())), None, diff --git a/packages/storage-plus/src/snapshot/mod.rs b/packages/storage-plus/src/snapshot/mod.rs index e8a587d1f..cdf3abc71 100644 --- a/packages/storage-plus/src/snapshot/mod.rs +++ b/packages/storage-plus/src/snapshot/mod.rs @@ -79,7 +79,7 @@ where // most recent checkpoint let checkpoint = self .checkpoints - .range(store, None, None, Order::Descending) + .range_raw(store, None, None, Order::Descending) .next() .transpose()?; if let Some((height, _)) = checkpoint { diff --git a/packages/utils/src/pagination.rs b/packages/utils/src/pagination.rs index 615993561..b346fb776 100644 --- a/packages/utils/src/pagination.rs +++ b/packages/utils/src/pagination.rs @@ -73,7 +73,7 @@ mod test { let start = calc_range_start(start_after).map(Bound::exclusive); let holders: Vec<(String, usize)> = HOLDERS - .range(&deps.storage, start, None, Order::Ascending) + .range_raw(&deps.storage, start, None, Order::Ascending) .map(deser_holder_kv) .take(LIMIT) .collect(); @@ -102,7 +102,7 @@ mod test { let end = calc_range_end(end_before).map(Bound::exclusive); let holders: Vec<(String, usize)> = HOLDERS - .range(&deps.storage, None, end, Order::Descending) + .range_raw(&deps.storage, None, end, Order::Descending) .map(deser_holder_kv) .take(LIMIT) .collect(); From 05d185516cb2a374ded016a968e543cecd3a8798 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 07:44:54 +0100 Subject: [PATCH 07/47] Replace no_prefix() + range() by no_prefix() + range_raw() in indexes --- packages/storage-plus/src/indexes/multi.rs | 2 +- packages/storage-plus/src/indexes/unique.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 44e99c819..3d29a49df 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -216,7 +216,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } pub fn keys<'c>( diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 7b02ea7c2..f579cf8bd 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -170,7 +170,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } pub fn keys<'c>( From 57c470fe6e60ff76b4ba44fc9f08ce5665ae56a1 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 08:28:12 +0100 Subject: [PATCH 08/47] Replace no_prefix() + range() by no_prefix() + range_raw() in indexed maps --- packages/storage-plus/src/indexed_map.rs | 2 +- packages/storage-plus/src/indexed_snapshot.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index aa6e0d8c7..3b0e59d40 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -164,7 +164,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } } diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index dc99fa3f5..1b4e6b206 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -209,7 +209,7 @@ where where T: 'c, { - self.no_prefix().range(store, min, max, order) + self.no_prefix().range_raw(store, min, max, order) } } From 249b35f5755c6d222901abf98a545c2305879f8f Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 08:42:53 +0100 Subject: [PATCH 09/47] Replace prefix() + range() by prefix_de() + range_raw() in unique index Remove UniqueIndex::prefix() --- packages/storage-plus/src/indexed_map.rs | 4 ++-- packages/storage-plus/src/indexed_snapshot.rs | 4 ++-- packages/storage-plus/src/indexes/unique.rs | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 3b0e59d40..cab7ed47d 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -937,8 +937,8 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 1b4e6b206..c62d2ff15 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -925,8 +925,8 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index f579cf8bd..1075746e1 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -112,16 +112,6 @@ where k.joined_key() } - pub fn prefix(&self, p: IK::Prefix) -> Prefix, T> { - Prefix::with_deserialization_functions( - self.idx_namespace, - &p.prefix(), - &[], - |_, _, kv| deserialize_unique_v(kv), - |_, _, kv| deserialize_unique_v(kv), - ) - } - pub fn sub_prefix(&self, p: IK::SubPrefix) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, From a2b64b8beea8166a2f4628b82426ab738b00295a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 08:44:10 +0100 Subject: [PATCH 10/47] Remove UniqueIndex::sub_prefix --- packages/storage-plus/src/indexes/unique.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 1075746e1..dc1a3e45d 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -112,16 +112,6 @@ where k.joined_key() } - pub fn sub_prefix(&self, p: IK::SubPrefix) -> Prefix, T> { - Prefix::with_deserialization_functions( - self.idx_namespace, - &p.prefix(), - &[], - |_, _, kv| deserialize_unique_v(kv), - |_, _, kv| deserialize_unique_v(kv), - ) - } - fn no_prefix(&self) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, From 40a587f2ba86422e9016956e3e3801e45065825b Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 09:10:57 +0100 Subject: [PATCH 11/47] Replace prefix() + range() by prefix_de() + range_raw() in multi index Remove MultiIndex::prefix() Adjust MultiIndex::no_prefix() trait bounds --- packages/storage-plus/src/indexed_map.rs | 26 ++++++++-------- packages/storage-plus/src/indexed_snapshot.rs | 26 ++++++++-------- packages/storage-plus/src/indexes/multi.rs | 31 +++++++++---------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index cab7ed47d..901694853 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -414,8 +414,8 @@ mod test { let count = map .idx .name - .prefix("Maria".to_string()) - .range(&store, None, None, Order::Ascending) + .prefix_de("Maria".to_string()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(2, count); @@ -423,8 +423,8 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix("Maria".to_string()) - .range(&store, None, None, Order::Ascending) + .prefix_de("Maria".to_string()) + .range_raw(&store, None, None, Order::Ascending) .collect::>() .unwrap(); assert_eq!(2, marias.len()); @@ -436,8 +436,8 @@ mod test { let count = map .idx .name - .prefix("Marib".to_string()) - .range(&store, None, None, Order::Ascending) + .prefix_de("Marib".to_string()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -445,8 +445,8 @@ mod test { let count = map .idx .name - .prefix("Mari`".to_string()) - .range(&store, None, None, Order::Ascending) + .prefix_de("Mari`".to_string()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -454,8 +454,8 @@ mod test { let count = map .idx .name - .prefix("Maria5".to_string()) - .range(&store, None, None, Order::Ascending) + .prefix_de("Maria5".to_string()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -560,8 +560,8 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix("Maria".to_string()) - .range(&store, None, None, Order::Descending) + .prefix_de("Maria".to_string()) + .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -827,7 +827,7 @@ mod test { -> usize { map.idx .name - .prefix(name.to_string()) + .prefix_de(name.to_string()) .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index c62d2ff15..c022322be 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -430,8 +430,8 @@ mod test { let count = map .idx .name - .prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(2, count); @@ -439,8 +439,8 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .collect::>() .unwrap(); assert_eq!(2, marias.len()); @@ -452,8 +452,8 @@ mod test { let count = map .idx .name - .prefix(b"Marib".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Marib".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -461,8 +461,8 @@ mod test { let count = map .idx .name - .prefix(b"Mari`".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Mari`".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -470,8 +470,8 @@ mod test { let count = map .idx .name - .prefix(b"Maria5".to_vec()) - .range(&store, None, None, Order::Ascending) + .prefix_de(b"Maria5".to_vec()) + .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -532,8 +532,8 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Descending) + .prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -818,7 +818,7 @@ mod test { -> usize { map.idx .name - .prefix(name.as_bytes().to_vec()) + .prefix_de(name.as_bytes().to_vec()) .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 3d29a49df..2e0dbbcd6 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -143,16 +143,23 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a> + Prefixer<'a>, { - pub fn prefix(&self, p: IK) -> Prefix, T> { + fn no_prefix(&self) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, - &p.prefix(), + &[], self.pk_namespace, deserialize_multi_v, deserialize_multi_v, ) } +} +impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK> +where + PK: PrimaryKey<'a> + KeyDeserialize, + T: Serialize + DeserializeOwned + Clone, + IK: PrimaryKey<'a> + Prefixer<'a>, +{ pub fn sub_prefix(&self, p: IK::Prefix) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, @@ -163,29 +170,19 @@ where ) } - fn no_prefix(&self) -> Prefix, T> { - Prefix::with_deserialization_functions( - self.idx_namespace, - &[], - self.pk_namespace, - deserialize_multi_v, - deserialize_multi_v, - ) - } - pub fn index_key(&self, k: IK) -> Vec { k.joined_extra_key(b"") } #[cfg(test)] pub fn count(&self, store: &dyn Storage, p: IK) -> usize { - let prefix = self.prefix(p); + let prefix = self.prefix_de(p); prefix.keys_raw(store, None, None, Order::Ascending).count() } #[cfg(test)] pub fn all_pks(&self, store: &dyn Storage, p: IK) -> Vec> { - let prefix = self.prefix(p); + let prefix = self.prefix_de(p); prefix .keys_raw(store, None, None, Order::Ascending) .collect::>>() @@ -193,8 +190,10 @@ where #[cfg(test)] pub fn all_items(&self, store: &dyn Storage, p: IK) -> StdResult>> { - let prefix = self.prefix(p); - prefix.range(store, None, None, Order::Ascending).collect() + let prefix = self.prefix_de(p); + prefix + .range_raw(store, None, None, Order::Ascending) + .collect() } } From a2112abd3165fab5e308305899e95197831ba517 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 09:15:42 +0100 Subject: [PATCH 12/47] Replace sub_prefix() + range() by sub_prefix_de() + range_raw() in multi index Remove MultiIndex::sub_prefix --- packages/storage-plus/src/indexed_map.rs | 4 ++-- packages/storage-plus/src/indexed_snapshot.rs | 4 ++-- packages/storage-plus/src/indexes/multi.rs | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 901694853..592becca0 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -676,8 +676,8 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Descending) + .sub_prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index c022322be..ff9655662 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -657,8 +657,8 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix(b"Maria".to_vec()) - .range(&store, None, None, Order::Descending) + .sub_prefix_de(b"Maria".to_vec()) + .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 2e0dbbcd6..ee574f45b 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -160,16 +160,6 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a> + Prefixer<'a>, { - pub fn sub_prefix(&self, p: IK::Prefix) -> Prefix, T> { - Prefix::with_deserialization_functions( - self.idx_namespace, - &p.prefix(), - self.pk_namespace, - deserialize_multi_v, - deserialize_multi_v, - ) - } - pub fn index_key(&self, k: IK) -> Vec { k.joined_extra_key(b"") } From 69d26042860990021d81ae0922c3167b8e147f07 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 09:30:20 +0100 Subject: [PATCH 13/47] Remove Prefix::range --- packages/storage-plus/src/map.rs | 2 +- packages/storage-plus/src/prefix.rs | 44 +++++++++-------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 5917a09c7..c1f2e4b4d 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -1104,7 +1104,7 @@ mod test { // typical range under one prefix as a control let fives = AGES .prefix_de(5) - .range(&store, None, None, Order::Ascending) + .range_de(&store, None, None, Order::Ascending) .collect::>>() .unwrap(); assert_eq!(fives.len(), 2); diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index 8a4335b25..f522de923 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -164,24 +164,6 @@ where Box::new(mapped) } - pub fn range<'a>( - &self, - store: &'a dyn Storage, - min: Option, - max: Option, - order: Order, - ) -> Box> + 'a> - where - T: 'a, - K::Output: 'a, - { - let de_fn = self.de_fn_kv; - let pk_name = self.pk_name.clone(); - let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) - .map(move |kv| (de_fn)(store, &*pk_name, kv)); - Box::new(mapped) - } - pub fn keys_raw<'a>( &self, store: &'a dyn Storage, @@ -368,16 +350,18 @@ mod test { let expected_reversed: Vec<(Vec, u64)> = expected.iter().rev().cloned().collect(); // let's do the basic sanity check - let res: StdResult> = prefix.range(&store, None, None, Order::Ascending).collect(); + let res: StdResult> = prefix + .range_raw(&store, None, None, Order::Ascending) + .collect(); assert_eq!(&expected, &res.unwrap()); let res: StdResult> = prefix - .range(&store, None, None, Order::Descending) + .range_raw(&store, None, None, Order::Descending) .collect(); assert_eq!(&expected_reversed, &res.unwrap()); // now let's check some ascending ranges let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Inclusive(b"ra".to_vec())), None, @@ -387,7 +371,7 @@ mod test { assert_eq!(&expected[1..], res.unwrap().as_slice()); // skip excluded let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Exclusive(b"ra".to_vec())), None, @@ -397,7 +381,7 @@ mod test { assert_eq!(&expected[2..], res.unwrap().as_slice()); // if we exclude something a little lower, we get matched let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Exclusive(b"r".to_vec())), None, @@ -408,7 +392,7 @@ mod test { // now let's check some descending ranges let res: StdResult> = prefix - .range( + .range_raw( &store, None, Some(Bound::Inclusive(b"ra".to_vec())), @@ -418,7 +402,7 @@ mod test { assert_eq!(&expected_reversed[1..], res.unwrap().as_slice()); // skip excluded let res: StdResult> = prefix - .range( + .range_raw( &store, None, Some(Bound::Exclusive(b"ra".to_vec())), @@ -428,7 +412,7 @@ mod test { assert_eq!(&expected_reversed[2..], res.unwrap().as_slice()); // if we exclude something a little higher, we get matched let res: StdResult> = prefix - .range( + .range_raw( &store, None, Some(Bound::Exclusive(b"rb".to_vec())), @@ -439,7 +423,7 @@ mod test { // now test when both sides are set let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Inclusive(b"ra".to_vec())), Some(Bound::Exclusive(b"zi".to_vec())), @@ -449,7 +433,7 @@ mod test { assert_eq!(&expected[1..2], res.unwrap().as_slice()); // and descending let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Inclusive(b"ra".to_vec())), Some(Bound::Exclusive(b"zi".to_vec())), @@ -459,7 +443,7 @@ mod test { assert_eq!(&expected[1..2], res.unwrap().as_slice()); // Include both sides let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Inclusive(b"ra".to_vec())), Some(Bound::Inclusive(b"zi".to_vec())), @@ -469,7 +453,7 @@ mod test { assert_eq!(&expected_reversed[..2], res.unwrap().as_slice()); // Exclude both sides let res: StdResult> = prefix - .range( + .range_raw( &store, Some(Bound::Exclusive(b"ra".to_vec())), Some(Bound::Exclusive(b"zi".to_vec())), From e6e1926d342487504ff4ffd6f91f65d4e2179e32 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 10:07:29 +0100 Subject: [PATCH 14/47] Rename keys/range to keys_raw/range_raw in indexes --- packages/storage-plus/src/indexed_map.rs | 8 ++++---- packages/storage-plus/src/indexed_snapshot.rs | 2 +- packages/storage-plus/src/indexes/multi.rs | 4 ++-- packages/storage-plus/src/indexes/unique.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 592becca0..bc9fb93a8 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -469,7 +469,7 @@ mod test { let count = map .idx .name - .range(&store, Some(Bound::inclusive(key)), None, Order::Ascending) + .range_raw(&store, Some(Bound::inclusive(key)), None, Order::Ascending) .count(); // gets from the first "Maria" until the end assert_eq!(4, count); @@ -484,7 +484,7 @@ mod test { let count = map .idx .name - .range(&store, Some(Bound::exclusive(key)), None, Order::Ascending) + .range_raw(&store, Some(Bound::exclusive(key)), None, Order::Ascending) .count(); // gets from the 2nd "Maria" until the end assert_eq!(3, count); @@ -497,7 +497,7 @@ mod test { let count = map .idx .age - .range( + .range_raw( &store, Some(Bound::inclusive(age_key)), None, @@ -871,7 +871,7 @@ mod test { let res: StdResult> = map .idx .age - .range(&store, None, None, Order::Ascending) + .range_raw(&store, None, None, Order::Ascending) .collect(); let ages = res.unwrap(); diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index ff9655662..1015333f4 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -863,7 +863,7 @@ mod test { let res: StdResult> = map .idx .age - .range(&store, None, None, Order::Ascending) + .range_raw(&store, None, None, Order::Ascending) .collect(); let ages = res.unwrap(); diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index ee574f45b..b1453752f 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -195,7 +195,7 @@ where { // I would prefer not to copy code from Prefix, but no other way // with lifetimes (create Prefix inside function and return ref = no no) - pub fn range<'c>( + pub fn range_raw<'c>( &'c self, store: &'c dyn Storage, min: Option, @@ -208,7 +208,7 @@ where self.no_prefix().range_raw(store, min, max, order) } - pub fn keys<'c>( + pub fn keys_raw<'c>( &'c self, store: &'c dyn Storage, min: Option, diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index dc1a3e45d..dcdb40744 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -140,7 +140,7 @@ where { // I would prefer not to copy code from Prefix, but no other way // with lifetimes (create Prefix inside function and return ref = no no) - pub fn range<'c>( + pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -153,7 +153,7 @@ where self.no_prefix().range_raw(store, min, max, order) } - pub fn keys<'c>( + pub fn keys_raw<'c>( &self, store: &'c dyn Storage, min: Option, From 938b897dadad520b5b458af62ab31f769a19f19d Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 10:18:58 +0100 Subject: [PATCH 15/47] Rename keys/range to keys_raw/range_raw in indexed maps --- packages/storage-plus/src/indexed_map.rs | 12 +++++++++++- packages/storage-plus/src/indexed_snapshot.rs | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index bc9fb93a8..5d39e6cfb 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -154,7 +154,7 @@ where { // I would prefer not to copy code from Prefix, but no other way // with lifetimes (create Prefix inside function and return ref = no no) - pub fn range<'c>( + pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -166,6 +166,16 @@ where { self.no_prefix().range_raw(store, min, max, order) } + + pub fn keys_raw<'c>( + &self, + store: &'c dyn Storage, + min: Option, + max: Option, + order: cosmwasm_std::Order, + ) -> Box> + 'c> { + self.no_prefix().keys_raw(store, min, max, order) + } } #[cfg(feature = "iterator")] diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 1015333f4..4b291a7d3 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -199,7 +199,7 @@ where { // I would prefer not to copy code from Prefix, but no other way // with lifetimes (create Prefix inside function and return ref = no no) - pub fn range<'c>( + pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -211,6 +211,16 @@ where { self.no_prefix().range_raw(store, min, max, order) } + + pub fn keys_raw<'c>( + &self, + store: &'c dyn Storage, + min: Option, + max: Option, + order: cosmwasm_std::Order, + ) -> Box> + 'c> { + self.no_prefix().keys_raw(store, min, max, order) + } } #[cfg(feature = "iterator")] From 0e1af087216c96b2967bbb2d92b18ddbbe1acfa1 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 12:53:25 +0100 Subject: [PATCH 16/47] Rename keys/range to keys_raw/range_raw in snampshot map --- contracts/cw4-group/src/contract.rs | 2 +- contracts/cw4-stake/src/contract.rs | 2 +- packages/storage-plus/src/snapshot/map.rs | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/contracts/cw4-group/src/contract.rs b/contracts/cw4-group/src/contract.rs index 1600d020e..e0a34d3f1 100644 --- a/contracts/cw4-group/src/contract.rs +++ b/contracts/cw4-group/src/contract.rs @@ -193,7 +193,7 @@ fn list_members( let start = addr.map(|addr| Bound::exclusive(addr.to_string())); let members: StdResult> = MEMBERS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (key, weight) = item?; diff --git a/contracts/cw4-stake/src/contract.rs b/contracts/cw4-stake/src/contract.rs index 2b4d86774..20aa3b6f2 100644 --- a/contracts/cw4-stake/src/contract.rs +++ b/contracts/cw4-stake/src/contract.rs @@ -342,7 +342,7 @@ fn list_members( let start = addr.map(|addr| Bound::exclusive(addr.as_ref())); let members: StdResult> = MEMBERS - .range(deps.storage, start, None, Order::Ascending) + .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { let (key, weight) = item?; diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 24b03ccc0..90e84e5fd 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -164,7 +164,7 @@ where { // I would prefer not to copy code from Prefix, but no other way // with lifetimes (create Prefix inside function and return ref = no no) - pub fn range<'c>( + pub fn range_raw<'c>( &self, store: &'c dyn Storage, min: Option, @@ -176,6 +176,19 @@ where { self.no_prefix().range_raw(store, min, max, order) } + + pub fn keys_raw<'c>( + &self, + store: &'c dyn Storage, + min: Option, + max: Option, + order: cosmwasm_std::Order, + ) -> Box> + 'c> + where + T: 'c, + { + self.no_prefix().keys_raw(store, min, max, order) + } } #[cfg(feature = "iterator")] From 3542f03f164c6352a810fb1e75127431168c4d6f Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 12:54:39 +0100 Subject: [PATCH 17/47] Remove sub_/prefix() from indexed maps --- packages/storage-plus/src/indexed_map.rs | 10 ---------- packages/storage-plus/src/indexed_snapshot.rs | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 5d39e6cfb..8fb32463e 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -129,16 +129,6 @@ where self.primary.may_load(store, key) } - // use prefix to scan -> range - pub fn prefix(&self, p: K::Prefix) -> Prefix, T> { - Prefix::new(self.pk_namespace, &p.prefix()) - } - - // use sub_prefix to scan -> range - pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { - Prefix::new(self.pk_namespace, &p.prefix()) - } - // use no_prefix to scan -> range fn no_prefix(&self) -> Prefix, T> { Prefix::new(self.pk_namespace, &[]) diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 4b291a7d3..344c1eb81 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -174,16 +174,6 @@ where self.primary.may_load(store, key) } - // use prefix to scan -> range - pub fn prefix(&self, p: K::Prefix) -> Prefix, T> { - Prefix::new(self.pk_namespace, &p.prefix()) - } - - // use sub_prefix to scan -> range - pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix, T> { - Prefix::new(self.pk_namespace, &p.prefix()) - } - // use no_prefix to scan -> range pub fn no_prefix(&self) -> Prefix, T> { Prefix::new(self.pk_namespace, &[]) From 6fc2608d7e8eb46d5b1ba022f3baea5f26030b95 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 12:58:27 +0100 Subject: [PATCH 18/47] Rename prefix_range to prefix_range_raw --- packages/storage-plus/src/map.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index c1f2e4b4d..08581f170 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -138,7 +138,7 @@ where /// itself, and iterates over those (inclusively or exclusively, depending on `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range<'c>( + pub fn prefix_range_raw<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -1031,7 +1031,7 @@ mod test { // using inclusive bounds both sides let include = AGES - .prefix_range( + .prefix_range_raw( &store, Some(PrefixBound::inclusive(3u32)), Some(PrefixBound::inclusive(7u32)), @@ -1045,7 +1045,7 @@ mod test { // using exclusive bounds both sides let exclude = AGES - .prefix_range( + .prefix_range_raw( &store, Some(PrefixBound::exclusive(3u32)), Some(PrefixBound::exclusive(7u32)), @@ -1059,7 +1059,7 @@ mod test { // using inclusive in descending let include = AGES - .prefix_range( + .prefix_range_raw( &store, Some(PrefixBound::inclusive(3u32)), Some(PrefixBound::inclusive(5u32)), @@ -1073,7 +1073,7 @@ mod test { // using exclusive in descending let include = AGES - .prefix_range( + .prefix_range_raw( &store, Some(PrefixBound::exclusive(2u32)), Some(PrefixBound::exclusive(5u32)), From 8a0d2eb73844b9621edf807b868d32389cfd35a4 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 13:03:09 +0100 Subject: [PATCH 19/47] Rename prefix_range to prefix_range_raw in indexed map --- packages/storage-plus/src/indexed_map.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 8fb32463e..f703bcbde 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -180,7 +180,7 @@ where /// itself, and iterates over those (inclusively or exclusively, depending on `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range<'c>( + pub fn prefix_range_raw<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -1429,7 +1429,7 @@ mod test { let items: Vec<_> = map .idx .secondary - .prefix_range( + .prefix_range_raw( &store, None, Some(PrefixBound::inclusive(1u64)), From d58272896dabfa2078ac8f9f796268384e243b56 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 13:03:50 +0100 Subject: [PATCH 20/47] Rename prefix_range to prefix_range_raw in multi index --- packages/storage-plus/src/indexes/multi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index b1453752f..48822878e 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -224,7 +224,7 @@ where /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range<'c>( + pub fn prefix_range_raw<'c>( &'c self, store: &'c dyn Storage, min: Option>, From 2f6b4cb3bdeb5cf418360ecbae3e8bcde79e3361 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 13:30:27 +0100 Subject: [PATCH 21/47] Remove useless dereference --- packages/storage-plus/src/prefix.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index f522de923..5ce9bf159 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -160,7 +160,7 @@ where let de_fn = self.de_fn_v; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) - .map(move |kv| (de_fn)(store, &*pk_name, kv)); + .map(move |kv| (de_fn)(store, &pk_name, kv)); Box::new(mapped) } @@ -190,7 +190,7 @@ where let de_fn = self.de_fn_kv; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) - .map(move |kv| (de_fn)(store, &*pk_name, kv)); + .map(move |kv| (de_fn)(store, &pk_name, kv)); Box::new(mapped) } @@ -208,7 +208,7 @@ where let de_fn = self.de_fn_kv; let pk_name = self.pk_name.clone(); let mapped = range_with_prefix(store, &self.storage_prefix, min, max, order) - .map(move |kv| (de_fn)(store, &*pk_name, kv).map(|(k, _)| Ok(k))) + .map(move |kv| (de_fn)(store, &pk_name, kv).map(|(k, _)| Ok(k))) .flatten(); Box::new(mapped) } From bb3137c9590d74ce8d9a903d5e1d02334c97ec2a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 13:33:52 +0100 Subject: [PATCH 22/47] Rename keys_/range_de to keys/range in Prefix --- packages/storage-plus/src/indexed_map.rs | 18 +++++++++--------- packages/storage-plus/src/indexed_snapshot.rs | 14 +++++++------- packages/storage-plus/src/indexes/multi.rs | 4 ++-- packages/storage-plus/src/indexes/unique.rs | 4 ++-- packages/storage-plus/src/map.rs | 14 +++++++------- packages/storage-plus/src/prefix.rs | 4 ++-- packages/storage-plus/src/snapshot/map.rs | 8 ++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index f703bcbde..89d0388c0 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -255,7 +255,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -269,7 +269,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } fn no_prefix_de(&self) -> Prefix { @@ -617,7 +617,7 @@ mod test { .idx .name .prefix_de("Maria".to_string()) - .range_de(&store, None, None, Order::Descending) + .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -738,7 +738,7 @@ mod test { .idx .name_age .sub_prefix_de(b"Maria".to_vec()) - .range_de(&store, None, None, Order::Descending) + .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -967,7 +967,7 @@ mod test { .idx .name_lastname .prefix_de(b"Maria".to_vec()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); @@ -1041,7 +1041,7 @@ mod test { // type checks let all: StdResult> = map .prefix_de(()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!( @@ -1100,7 +1100,7 @@ mod test { // let's prefix and iterate let result: StdResult> = map .prefix_de("2") - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); assert_eq!( @@ -1155,7 +1155,7 @@ mod test { // let's prefix and iterate let result: StdResult> = map .prefix_de(("1", "2")) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); assert_eq!(result, [("5628".to_string(), data2),]); @@ -1207,7 +1207,7 @@ mod test { // let's sub-prefix and iterate let result: StdResult> = map .sub_prefix_de("1") - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); assert_eq!( diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 344c1eb81..415cac5cd 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -271,7 +271,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -285,7 +285,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } fn no_prefix_de(&self) -> Prefix { @@ -593,7 +593,7 @@ mod test { .idx .name .prefix_de(b"Maria".to_vec()) - .range_de(&store, None, None, Order::Descending) + .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -724,7 +724,7 @@ mod test { .idx .name_age .sub_prefix_de(b"Maria".to_vec()) - .range_de(&store, None, None, Order::Descending) + .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); let count = marias.len(); @@ -955,7 +955,7 @@ mod test { .idx .name_lastname .prefix_de(b"Maria".to_vec()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); @@ -1029,7 +1029,7 @@ mod test { // type checks let all: StdResult> = map .prefix_de(()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!( @@ -1056,7 +1056,7 @@ mod test { // type checks let all: StdResult> = map .sub_prefix_de(()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!( diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 48822878e..99f46eaae 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -312,7 +312,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -326,7 +326,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } fn no_prefix_de(&self) -> Prefix { diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index dcdb40744..38adff44a 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -207,7 +207,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -221,7 +221,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } pub fn prefix_de(&self, p: IK::Prefix) -> Prefix { diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 08581f170..19818d343 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -222,7 +222,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -236,7 +236,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } fn no_prefix_de(&self) -> Prefix { @@ -648,7 +648,7 @@ mod test { // let's try to iterate over a prefix_de let all: StdResult> = ALLOWANCE .prefix_de(b"owner") - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -776,7 +776,7 @@ mod test { // let's iterate over a sub_prefix_de let all: StdResult> = TRIPLE .sub_prefix_de(b"owner") - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(3, all.len()); @@ -792,7 +792,7 @@ mod test { // let's iterate over a prefix_de let all: StdResult> = TRIPLE .prefix_de((b"owner", 9)) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -1104,7 +1104,7 @@ mod test { // typical range under one prefix as a control let fives = AGES .prefix_de(5) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect::>>() .unwrap(); assert_eq!(fives.len(), 2); @@ -1115,7 +1115,7 @@ mod test { let keys: Vec<_> = AGES .no_prefix_de() - .keys_de(&store, None, None, Order::Ascending) + .keys(&store, None, None, Order::Ascending) .collect(); println!("keys: {:?}", keys); diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index 5ce9bf159..5c210052a 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -176,7 +176,7 @@ where Box::new(mapped) } - pub fn range_de<'a>( + pub fn range<'a>( &self, store: &'a dyn Storage, min: Option, @@ -194,7 +194,7 @@ where Box::new(mapped) } - pub fn keys_de<'a>( + pub fn keys<'a>( &self, store: &'a dyn Storage, min: Option, diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 90e84e5fd..8f50acaf6 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -232,7 +232,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range_de(store, min, max, order) + self.no_prefix_de().range(store, min, max, order) } pub fn keys_de<'c>( @@ -246,7 +246,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys_de(store, min, max, order) + self.no_prefix_de().keys(store, min, max, order) } pub fn prefix_de(&self, p: K::Prefix) -> Prefix { @@ -557,7 +557,7 @@ mod tests { // let's prefix and iterate let all: StdResult> = EVERY_COMPOSITE_KEY .prefix_de("C") - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(1, all.len()); @@ -577,7 +577,7 @@ mod tests { // sub_prefix_de type checks let all: StdResult> = EVERY_COMPOSITE_KEY .sub_prefix_de(()) - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); From e06eb1456aef2ea6dc33dc14c277d73e85e00856 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:09:02 +0100 Subject: [PATCH 23/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in Map --- contracts/cw1155-base/src/contract.rs | 4 +- contracts/cw20-base/src/enumerable.rs | 2 +- contracts/cw20-ics20/src/contract.rs | 2 +- contracts/cw3-fixed-multisig/src/contract.rs | 2 +- contracts/cw3-flex-multisig/src/contract.rs | 2 +- packages/storage-plus/src/map.rs | 67 +++++++++----------- packages/storage-plus/src/snapshot/mod.rs | 4 +- 7 files changed, 38 insertions(+), 45 deletions(-) diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index 75c6ebbdf..74291b0f1 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -497,7 +497,7 @@ fn query_all_approvals( let start = start_after.map(|addr| Bound::exclusive(addr.as_ref())); let operators = APPROVES - .prefix_de(&owner) + .prefix(&owner) .range_raw(deps.storage, start, None, Order::Ascending) .filter(|r| include_expired || r.is_err() || !r.as_ref().unwrap().1.is_expired(&env.block)) .take(limit) @@ -516,7 +516,7 @@ fn query_tokens( let start = start_after.map(Bound::exclusive); let tokens = BALANCES - .prefix_de(&owner) + .prefix(&owner) .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| item.map(|(k, _)| String::from_utf8(k).unwrap())) diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index 319097ac3..7b6c526c8 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -19,7 +19,7 @@ pub fn query_all_allowances( let start = start_after.map(Bound::exclusive); let allowances: StdResult> = ALLOWANCES - .prefix_de(&owner_addr) + .prefix(&owner_addr) .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index d3c3f3f0b..03a806102 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -165,7 +165,7 @@ pub fn query_channel(deps: Deps, id: String) -> StdResult { let info = CHANNEL_INFO.load(deps.storage, &id)?; // this returns Vec<(outstanding, total)> let state: StdResult> = CHANNEL_STATE - .prefix_de(&id) + .prefix(&id) .range_raw(deps.storage, None, None, Order::Ascending) .map(|r| { let (k, v) = r?; diff --git a/contracts/cw3-fixed-multisig/src/contract.rs b/contracts/cw3-fixed-multisig/src/contract.rs index f99882a1d..48a600834 100644 --- a/contracts/cw3-fixed-multisig/src/contract.rs +++ b/contracts/cw3-fixed-multisig/src/contract.rs @@ -386,7 +386,7 @@ fn list_votes( let start = start_after.map(Bound::exclusive); let votes: StdResult> = BALLOTS - .prefix_de(proposal_id) + .prefix(proposal_id) .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index b508331b4..c7293d99c 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -383,7 +383,7 @@ fn list_votes( let start = addr.map(|addr| Bound::exclusive(addr.as_ref())); let votes: StdResult> = BALLOTS - .prefix_de(proposal_id) + .prefix(proposal_id) .range_raw(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 19818d343..602a1dc59 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -115,11 +115,11 @@ where T: Serialize + DeserializeOwned, K: PrimaryKey<'a>, { - pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix { + pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix { Prefix::new(self.namespace, &p.prefix()) } - pub fn prefix_de(&self, p: K::Prefix) -> Prefix { + pub fn prefix(&self, p: K::Prefix) -> Prefix { Prefix::new(self.namespace, &p.prefix()) } } @@ -187,13 +187,13 @@ where T: Serialize + DeserializeOwned, K: PrimaryKey<'a> + KeyDeserialize, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -211,7 +211,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -225,7 +225,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, @@ -474,9 +474,7 @@ mod test { PEOPLE.save(&mut store, b"jim", &data2).unwrap(); // let's try to iterate! - let all: StdResult> = PEOPLE - .range_de(&store, None, None, Order::Ascending) - .collect(); + let all: StdResult> = PEOPLE.range(&store, None, None, Order::Ascending).collect(); let all = all.unwrap(); assert_eq!(2, all.len()); assert_eq!( @@ -489,7 +487,7 @@ mod test { // let's try to iterate over a range let all: StdResult> = PEOPLE - .range_de( + .range( &store, Some(Bound::Inclusive(b"j".to_vec())), None, @@ -505,7 +503,7 @@ mod test { // let's try to iterate over a more restrictive range let all: StdResult> = PEOPLE - .range_de( + .range( &store, Some(Bound::Inclusive(b"jo".to_vec())), None, @@ -537,7 +535,7 @@ mod test { // let's try to iterate! let all: StdResult> = PEOPLE_ID - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -545,7 +543,7 @@ mod test { // let's try to iterate over a range let all: StdResult> = PEOPLE_ID - .range_de( + .range( &store, Some(Bound::inclusive_int(56u32)), None, @@ -558,7 +556,7 @@ mod test { // let's try to iterate over a more restrictive range let all: StdResult> = PEOPLE_ID - .range_de( + .range( &store, Some(Bound::inclusive_int(57u32)), None, @@ -603,7 +601,7 @@ mod test { // let's try to iterate over a prefix let all: StdResult> = ALLOWANCE - .prefix_de(b"owner") + .prefix(b"owner") .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -632,7 +630,7 @@ mod test { // let's try to iterate! let all: StdResult> = ALLOWANCE - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(3, all.len()); @@ -647,7 +645,7 @@ mod test { // let's try to iterate over a prefix_de let all: StdResult> = ALLOWANCE - .prefix_de(b"owner") + .prefix(b"owner") .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -707,7 +705,7 @@ mod test { // let's iterate over a prefix let all: StdResult> = TRIPLE - .prefix_de((b"owner", 9)) + .prefix((b"owner", 9)) .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -722,7 +720,7 @@ mod test { // let's iterate over a sub prefix let all: StdResult> = TRIPLE - .sub_prefix_de(b"owner") + .sub_prefix(b"owner") .range_raw(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -758,9 +756,7 @@ mod test { .unwrap(); // let's try to iterate! - let all: StdResult> = TRIPLE - .range_de(&store, None, None, Order::Ascending) - .collect(); + let all: StdResult> = TRIPLE.range(&store, None, None, Order::Ascending).collect(); let all = all.unwrap(); assert_eq!(4, all.len()); assert_eq!( @@ -775,7 +771,7 @@ mod test { // let's iterate over a sub_prefix_de let all: StdResult> = TRIPLE - .sub_prefix_de(b"owner") + .sub_prefix(b"owner") .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -791,7 +787,7 @@ mod test { // let's iterate over a prefix_de let all: StdResult> = TRIPLE - .prefix_de((b"owner", 9)) + .prefix((b"owner", 9)) .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -977,7 +973,7 @@ mod test { // get all under one key let all: StdResult> = ALLOWANCE - .prefix_de(b"owner") + .prefix(b"owner") .range_raw(&store, None, None, Order::Ascending) .collect(); assert_eq!( @@ -987,7 +983,7 @@ mod test { // Or ranges between two items (even reverse) let all: StdResult> = ALLOWANCE - .prefix_de(b"owner") + .prefix(b"owner") .range_raw( &store, Some(Bound::Exclusive(b"spender1".to_vec())), @@ -1017,7 +1013,7 @@ mod test { // typical range under one prefix as a control let fives = AGES - .prefix_de(5) + .prefix(5) .range_raw(&store, None, None, Order::Ascending) .collect::>>() .unwrap(); @@ -1103,7 +1099,7 @@ mod test { // typical range under one prefix as a control let fives = AGES - .prefix_de(5) + .prefix(5) .range(&store, None, None, Order::Ascending) .collect::>>() .unwrap(); @@ -1113,15 +1109,12 @@ mod test { vec![("789".to_string(), 789), ("987".to_string(), 987)] ); - let keys: Vec<_> = AGES - .no_prefix_de() - .keys(&store, None, None, Order::Ascending) - .collect(); + let keys: Vec<_> = AGES.keys(&store, None, None, Order::Ascending).collect(); println!("keys: {:?}", keys); // using inclusive bounds both sides let include = AGES - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive(3u32)), Some(PrefixBound::inclusive(7u32)), @@ -1135,7 +1128,7 @@ mod test { // using exclusive bounds both sides let exclude = AGES - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::exclusive(3u32)), Some(PrefixBound::exclusive(7u32)), @@ -1149,7 +1142,7 @@ mod test { // using inclusive in descending let include = AGES - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive(3u32)), Some(PrefixBound::inclusive(5u32)), @@ -1163,7 +1156,7 @@ mod test { // using exclusive in descending let include = AGES - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::exclusive(2u32)), Some(PrefixBound::exclusive(5u32)), diff --git a/packages/storage-plus/src/snapshot/mod.rs b/packages/storage-plus/src/snapshot/mod.rs index cdf3abc71..c20fe2e8d 100644 --- a/packages/storage-plus/src/snapshot/mod.rs +++ b/packages/storage-plus/src/snapshot/mod.rs @@ -87,7 +87,7 @@ where let start = Bound::inclusive(height); let first = self .changelog - .prefix_de(k.clone()) + .prefix(k.clone()) .range_raw(store, Some(start), None, Order::Ascending) .next() .transpose()?; @@ -146,7 +146,7 @@ where let start = Bound::inclusive_int(height); let first = self .changelog - .prefix_de(key) + .prefix(key) .range_raw(store, Some(start), None, Order::Ascending) .next(); From fb36916c17be2728839e6c5e3092ed5543a36f04 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:23:53 +0100 Subject: [PATCH 24/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in SnapshotMap --- packages/storage-plus/src/snapshot/map.rs | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 8f50acaf6..a7a3b03c0 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -197,13 +197,13 @@ where T: Serialize + DeserializeOwned, K: PrimaryKey<'a> + KeyDeserialize, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -221,7 +221,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -235,7 +235,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, @@ -249,11 +249,11 @@ where self.no_prefix_de().keys(store, min, max, order) } - pub fn prefix_de(&self, p: K::Prefix) -> Prefix { + pub fn prefix(&self, p: K::Prefix) -> Prefix { Prefix::new(self.primary.namespace(), &p.prefix()) } - pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix { + pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix { Prefix::new(self.primary.namespace(), &p.prefix()) } @@ -467,16 +467,14 @@ mod tests { init_data(&EVERY, &mut store); // let's try to iterate! - let all: StdResult> = EVERY - .range_de(&store, None, None, Order::Ascending) - .collect(); + let all: StdResult> = EVERY.range(&store, None, None, Order::Ascending).collect(); let all = all.unwrap(); assert_eq!(2, all.len()); assert_eq!(all, vec![("C".into(), 13), ("D".into(), 22)]); // let's try to iterate over a range let all: StdResult> = EVERY - .range_de( + .range( &store, Some(Bound::Inclusive(b"C".to_vec())), None, @@ -489,7 +487,7 @@ mod tests { // let's try to iterate over a more restrictive range let all: StdResult> = EVERY - .range_de( + .range( &store, Some(Bound::Inclusive(b"D".to_vec())), None, @@ -511,7 +509,7 @@ mod tests { // let's try to iterate! let all: StdResult> = EVERY_COMPOSITE_KEY - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); assert_eq!(2, all.len()); @@ -534,7 +532,7 @@ mod tests { // let's prefix-range and iterate let all: StdResult> = EVERY_COMPOSITE_KEY - .prefix_range_de( + .prefix_range( &store, None, Some(PrefixBound::exclusive("C")), @@ -556,7 +554,7 @@ mod tests { // let's prefix and iterate let all: StdResult> = EVERY_COMPOSITE_KEY - .prefix_de("C") + .prefix("C") .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -576,7 +574,7 @@ mod tests { // This is similar to calling range() directly, but added here for completeness / // sub_prefix_de type checks let all: StdResult> = EVERY_COMPOSITE_KEY - .sub_prefix_de(()) + .sub_prefix(()) .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); From 32c0aae45ff7eafbf90eacbfaf4a176f91471e9a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:34:09 +0100 Subject: [PATCH 25/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in IndexedMap --- packages/storage-plus/src/indexed_map.rs | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 89d0388c0..b3b9f0b39 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -204,11 +204,11 @@ where K: PrimaryKey<'a>, I: IndexList, { - pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix { + pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix { Prefix::new(self.pk_namespace, &p.prefix()) } - pub fn prefix_de(&self, p: K::Prefix) -> Prefix { + pub fn prefix(&self, p: K::Prefix) -> Prefix { Prefix::new(self.pk_namespace, &p.prefix()) } } @@ -220,13 +220,13 @@ where K: PrimaryKey<'a> + KeyDeserialize, I: IndexList, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -244,7 +244,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -258,7 +258,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, @@ -994,7 +994,7 @@ mod test { let (pks, datas) = save_data(&mut store, &map); // let's try to iterate! - let all: StdResult> = map.range_de(&store, None, None, Order::Ascending).collect(); + let all: StdResult> = map.range(&store, None, None, Order::Ascending).collect(); let all = all.unwrap(); assert_eq!( all, @@ -1007,7 +1007,7 @@ mod test { // let's try to iterate over a range let all: StdResult> = map - .range_de( + .range( &store, Some(Bound::Inclusive(b"3".to_vec())), None, @@ -1040,7 +1040,7 @@ mod test { // This is similar to calling range() directly, but added here for completeness / prefix_de // type checks let all: StdResult> = map - .prefix_de(()) + .prefix(()) .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -1099,7 +1099,7 @@ mod test { // let's prefix and iterate let result: StdResult> = map - .prefix_de("2") + .prefix("2") .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); @@ -1154,7 +1154,7 @@ mod test { // let's prefix and iterate let result: StdResult> = map - .prefix_de(("1", "2")) + .prefix(("1", "2")) .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); @@ -1206,7 +1206,7 @@ mod test { // let's sub-prefix and iterate let result: StdResult> = map - .sub_prefix_de("1") + .sub_prefix("1") .range(&store, None, None, Order::Ascending) .collect(); let result = result.unwrap(); @@ -1264,7 +1264,7 @@ mod test { // let's try to iterate! let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive("2")), None, @@ -1283,7 +1283,7 @@ mod test { // let's try to iterate over a range let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive("2")), Some(PrefixBound::exclusive("3")), @@ -1345,7 +1345,7 @@ mod test { // let's prefix-range and iterate let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive(("1", "2"))), None, @@ -1373,7 +1373,7 @@ mod test { // let's prefix-range over inclusive bounds on both sides let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive(("1", "2"))), Some(PrefixBound::inclusive(("2", "1"))), From 4db106febf3f1e053755c25343d77160dc9915dd Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:40:27 +0100 Subject: [PATCH 26/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in IndexedSnapshotMap --- packages/storage-plus/src/indexed_snapshot.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 415cac5cd..d9aae62ca 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -220,11 +220,11 @@ where K: PrimaryKey<'a>, I: IndexList, { - pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix { + pub fn sub_prefix(&self, p: K::SubPrefix) -> Prefix { Prefix::new(self.pk_namespace, &p.prefix()) } - pub fn prefix_de(&self, p: K::Prefix) -> Prefix { + pub fn prefix(&self, p: K::Prefix) -> Prefix { Prefix::new(self.pk_namespace, &p.prefix()) } } @@ -236,13 +236,13 @@ where K: PrimaryKey<'a> + KeyDeserialize, I: IndexList, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -260,7 +260,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -274,7 +274,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, @@ -982,7 +982,7 @@ mod test { let (pks, datas) = save_data(&mut store, &map); // let's try to iterate! - let all: StdResult> = map.range_de(&store, None, None, Order::Ascending).collect(); + let all: StdResult> = map.range(&store, None, None, Order::Ascending).collect(); let all = all.unwrap(); assert_eq!( all, @@ -995,7 +995,7 @@ mod test { // let's try to iterate over a range let all: StdResult> = map - .range_de( + .range( &store, Some(Bound::Inclusive(b"3".to_vec())), None, @@ -1028,7 +1028,7 @@ mod test { // This is similar to calling range() directly, but added here for completeness / prefix_de // type checks let all: StdResult> = map - .prefix_de(()) + .prefix(()) .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -1055,7 +1055,7 @@ mod test { // This is similar to calling range() directly, but added here for completeness / sub_prefix_de // type checks let all: StdResult> = map - .sub_prefix_de(()) + .sub_prefix(()) .range(&store, None, None, Order::Ascending) .collect(); let all = all.unwrap(); @@ -1115,7 +1115,7 @@ mod test { // let's try to iterate! let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive("2")), None, @@ -1134,7 +1134,7 @@ mod test { // let's try to iterate over a range let result: StdResult> = map - .prefix_range_de( + .prefix_range( &store, Some(PrefixBound::inclusive("2")), Some(PrefixBound::exclusive("3")), From d835665429b206f7fcb2df26f5fa4405a96d6298 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:43:17 +0100 Subject: [PATCH 27/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in UniqueIndex --- packages/storage-plus/src/indexed_map.rs | 6 +++--- packages/storage-plus/src/indexed_snapshot.rs | 6 +++--- packages/storage-plus/src/indexes/unique.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index b3b9f0b39..49f6afb2d 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -904,7 +904,7 @@ mod test { let res: StdResult> = map .idx .age - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let ages = res.unwrap(); @@ -937,7 +937,7 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); @@ -966,7 +966,7 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index d9aae62ca..4ac7e0d00 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -894,7 +894,7 @@ mod test { let res: StdResult> = map .idx .age - .range_de(&store, None, None, Order::Ascending) + .range(&store, None, None, Order::Ascending) .collect(); let ages = res.unwrap(); @@ -925,7 +925,7 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); @@ -954,7 +954,7 @@ mod test { let res: StdResult> = map .idx .name_lastname - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range(&store, None, None, Order::Ascending) .collect(); let marias = res.unwrap(); diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 38adff44a..7796f9d1f 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -171,13 +171,13 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a>, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -196,7 +196,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -210,7 +210,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, @@ -224,7 +224,7 @@ where self.no_prefix_de().keys(store, min, max, order) } - pub fn prefix_de(&self, p: IK::Prefix) -> Prefix { + pub fn prefix(&self, p: IK::Prefix) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), @@ -234,7 +234,7 @@ where ) } - pub fn sub_prefix_de(&self, p: IK::SubPrefix) -> Prefix { + pub fn sub_prefix(&self, p: IK::SubPrefix) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), From 72a2f4a492558a47226634f8523d14cc5ac22381 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:45:33 +0100 Subject: [PATCH 28/47] Rename prefix_/prefix_range_/keys_/range_de to prefix/prefix_range/keys/range in MultiIndex --- packages/storage-plus/src/indexed_map.rs | 20 +++++++++---------- packages/storage-plus/src/indexed_snapshot.rs | 20 +++++++++---------- packages/storage-plus/src/indexes/multi.rs | 20 +++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index 49f6afb2d..afa08da9f 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -414,7 +414,7 @@ mod test { let count = map .idx .name - .prefix_de("Maria".to_string()) + .prefix("Maria".to_string()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(2, count); @@ -423,7 +423,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de("Maria".to_string()) + .prefix("Maria".to_string()) .range_raw(&store, None, None, Order::Ascending) .collect::>() .unwrap(); @@ -436,7 +436,7 @@ mod test { let count = map .idx .name - .prefix_de("Marib".to_string()) + .prefix("Marib".to_string()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -445,7 +445,7 @@ mod test { let count = map .idx .name - .prefix_de("Mari`".to_string()) + .prefix("Mari`".to_string()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -454,7 +454,7 @@ mod test { let count = map .idx .name - .prefix_de("Maria5".to_string()) + .prefix("Maria5".to_string()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -560,7 +560,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de("Maria".to_string()) + .prefix("Maria".to_string()) .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -616,7 +616,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de("Maria".to_string()) + .prefix("Maria".to_string()) .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -676,7 +676,7 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix_de(b"Maria".to_vec()) + .sub_prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -737,7 +737,7 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix_de(b"Maria".to_vec()) + .sub_prefix(b"Maria".to_vec()) .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -827,7 +827,7 @@ mod test { -> usize { map.idx .name - .prefix_de(name.to_string()) + .prefix(name.to_string()) .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 4ac7e0d00..955874880 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -430,7 +430,7 @@ mod test { let count = map .idx .name - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(2, count); @@ -439,7 +439,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Ascending) .collect::>() .unwrap(); @@ -452,7 +452,7 @@ mod test { let count = map .idx .name - .prefix_de(b"Marib".to_vec()) + .prefix(b"Marib".to_vec()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -461,7 +461,7 @@ mod test { let count = map .idx .name - .prefix_de(b"Mari`".to_vec()) + .prefix(b"Mari`".to_vec()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -470,7 +470,7 @@ mod test { let count = map .idx .name - .prefix_de(b"Maria5".to_vec()) + .prefix(b"Maria5".to_vec()) .range_raw(&store, None, None, Order::Ascending) .count(); assert_eq!(0, count); @@ -532,7 +532,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -592,7 +592,7 @@ mod test { let marias: Vec<_> = map .idx .name - .prefix_de(b"Maria".to_vec()) + .prefix(b"Maria".to_vec()) .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -657,7 +657,7 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix_de(b"Maria".to_vec()) + .sub_prefix(b"Maria".to_vec()) .range_raw(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -723,7 +723,7 @@ mod test { let marias: Vec<_> = map .idx .name_age - .sub_prefix_de(b"Maria".to_vec()) + .sub_prefix(b"Maria".to_vec()) .range(&store, None, None, Order::Descending) .collect::>() .unwrap(); @@ -818,7 +818,7 @@ mod test { -> usize { map.idx .name - .prefix_de(name.as_bytes().to_vec()) + .prefix(name.as_bytes().to_vec()) .keys_raw(store, None, None, Order::Ascending) .count() }; diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 99f46eaae..b9915e2b0 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -166,13 +166,13 @@ where #[cfg(test)] pub fn count(&self, store: &dyn Storage, p: IK) -> usize { - let prefix = self.prefix_de(p); + let prefix = self.prefix(p); prefix.keys_raw(store, None, None, Order::Ascending).count() } #[cfg(test)] pub fn all_pks(&self, store: &dyn Storage, p: IK) -> Vec> { - let prefix = self.prefix_de(p); + let prefix = self.prefix(p); prefix .keys_raw(store, None, None, Order::Ascending) .collect::>>() @@ -180,7 +180,7 @@ where #[cfg(test)] pub fn all_items(&self, store: &dyn Storage, p: IK) -> StdResult>> { - let prefix = self.prefix_de(p); + let prefix = self.prefix(p); prefix .range_raw(store, None, None, Order::Ascending) .collect() @@ -248,7 +248,7 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a> + Prefixer<'a>, { - pub fn prefix_de(&self, p: IK) -> Prefix { + pub fn prefix(&self, p: IK) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), @@ -258,7 +258,7 @@ where ) } - pub fn sub_prefix_de(&self, p: IK::Prefix) -> Prefix { + pub fn sub_prefix(&self, p: IK::Prefix) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &p.prefix(), @@ -276,13 +276,13 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a> + KeyDeserialize + Prefixer<'a>, { - /// While `range_de` over a `prefix_de` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range_de` accepts bounds for the lowest and highest elements of the + /// While `range` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. - pub fn prefix_range_de<'c>( + pub fn prefix_range<'c>( &self, store: &'c dyn Storage, min: Option>, @@ -301,7 +301,7 @@ where Box::new(mapped) } - pub fn range_de<'c>( + pub fn range<'c>( &self, store: &'c dyn Storage, min: Option, @@ -315,7 +315,7 @@ where self.no_prefix_de().range(store, min, max, order) } - pub fn keys_de<'c>( + pub fn keys<'c>( &self, store: &'c dyn Storage, min: Option, From b2f46bc7d641b27c104aa71e63e131f1db9836dd Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:52:25 +0100 Subject: [PATCH 29/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in Map for consistency --- packages/storage-plus/src/map.rs | 12 ++++++------ packages/storage-plus/src/snapshot/map.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 602a1dc59..c7f7fc02c 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -50,7 +50,7 @@ where } #[cfg(feature = "iterator")] - pub(crate) fn no_prefix(&self) -> Prefix, T> { + pub(crate) fn no_prefix_raw(&self) -> Prefix, T> { Prefix::new(self.namespace, &[]) } @@ -164,7 +164,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -177,7 +177,7 @@ where where T: 'c, { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } } @@ -222,7 +222,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -236,10 +236,10 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::new(self.namespace, &[]) } } diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index a7a3b03c0..5d190be49 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -70,7 +70,7 @@ where } fn no_prefix(&self) -> Prefix, T> { - self.primary.no_prefix() + self.primary.no_prefix_raw() } /// load old value and store changelog From 7d7f42506b7707349dad11b9f194fb3ae6faa22a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:54:44 +0100 Subject: [PATCH 30/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in IndexedMap for consistency --- packages/storage-plus/src/indexed_map.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index afa08da9f..b67dadb9a 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -130,7 +130,7 @@ where } // use no_prefix to scan -> range - fn no_prefix(&self) -> Prefix, T> { + fn no_prefix_raw(&self) -> Prefix, T> { Prefix::new(self.pk_namespace, &[]) } } @@ -154,7 +154,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -164,7 +164,7 @@ where max: Option, order: cosmwasm_std::Order, ) -> Box> + 'c> { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } } @@ -255,7 +255,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -269,10 +269,10 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::new(self.pk_namespace, &[]) } } From 1f1a87a6a1f9592ab455362c1291795ae19eab3a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:56:13 +0100 Subject: [PATCH 31/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in SnapshotMap for consistency --- packages/storage-plus/src/snapshot/map.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 5d190be49..030e08937 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -69,7 +69,7 @@ where self.primary.key(k) } - fn no_prefix(&self) -> Prefix, T> { + fn no_prefix_raw(&self) -> Prefix, T> { self.primary.no_prefix_raw() } @@ -174,7 +174,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -187,7 +187,7 @@ where where T: 'c, { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } } @@ -232,7 +232,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -246,7 +246,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } pub fn prefix(&self, p: K::Prefix) -> Prefix { @@ -257,7 +257,7 @@ where Prefix::new(self.primary.namespace(), &p.prefix()) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::new(self.primary.namespace(), &[]) } } From 42d5db965f6792d16306d174203d268687fac0cc Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:57:57 +0100 Subject: [PATCH 32/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in IndexedSnapshotMap for consistency --- packages/storage-plus/src/indexed_snapshot.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 955874880..2b7914186 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -175,7 +175,7 @@ where } // use no_prefix to scan -> range - pub fn no_prefix(&self) -> Prefix, T> { + pub fn no_prefix_raw(&self) -> Prefix, T> { Prefix::new(self.pk_namespace, &[]) } } @@ -199,7 +199,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -209,7 +209,7 @@ where max: Option, order: cosmwasm_std::Order, ) -> Box> + 'c> { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } } @@ -271,7 +271,7 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -285,10 +285,10 @@ where T: 'c, K::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::new(self.pk_namespace, &[]) } } From b37f1eb191b08257b55699481d17670bf044f082 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 18:59:49 +0100 Subject: [PATCH 33/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in UniqueIndex for consistency --- packages/storage-plus/src/indexes/unique.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 7796f9d1f..06c266fa1 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -112,7 +112,7 @@ where k.joined_key() } - fn no_prefix(&self) -> Prefix, T> { + fn no_prefix_raw(&self) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, &[], @@ -150,7 +150,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -160,7 +160,7 @@ where max: Option, order: Order, ) -> Box> + 'c> { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } } @@ -207,7 +207,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -221,7 +221,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } pub fn prefix(&self, p: IK::Prefix) -> Prefix { @@ -244,7 +244,7 @@ where ) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &[], From e7aabeac0ee8635cf7f94edeabad149f0331b380 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 19:00:50 +0100 Subject: [PATCH 34/47] Rename no_prefix to no_prefix_raw, no_prefix_de to no_prefix in MultiIndex for consistency --- packages/storage-plus/src/indexes/multi.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index b9915e2b0..499e7bb44 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -143,7 +143,7 @@ where T: Serialize + DeserializeOwned + Clone, IK: PrimaryKey<'a> + Prefixer<'a>, { - fn no_prefix(&self) -> Prefix, T> { + fn no_prefix_raw(&self) -> Prefix, T> { Prefix::with_deserialization_functions( self.idx_namespace, &[], @@ -205,7 +205,7 @@ where where T: 'c, { - self.no_prefix().range_raw(store, min, max, order) + self.no_prefix_raw().range_raw(store, min, max, order) } pub fn keys_raw<'c>( @@ -215,7 +215,7 @@ where max: Option, order: Order, ) -> Box> + 'c> { - self.no_prefix().keys_raw(store, min, max, order) + self.no_prefix_raw().keys_raw(store, min, max, order) } /// While `range` over a `prefix` fixes the prefix to one element and iterates over the @@ -312,7 +312,7 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().range(store, min, max, order) + self.no_prefix().range(store, min, max, order) } pub fn keys<'c>( @@ -326,10 +326,10 @@ where T: 'c, PK::Output: 'static, { - self.no_prefix_de().keys(store, min, max, order) + self.no_prefix().keys(store, min, max, order) } - fn no_prefix_de(&self) -> Prefix { + fn no_prefix(&self) -> Prefix { Prefix::with_deserialization_functions( self.idx_namespace, &[], From ed513e629cd6cdbf610e1cd8e0184df1b48da32c Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 20:30:14 +0100 Subject: [PATCH 35/47] Replace range_raw() plus manual deserialization by keys() --- packages/utils/src/pagination.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/utils/src/pagination.rs b/packages/utils/src/pagination.rs index b346fb776..7af917acd 100644 --- a/packages/utils/src/pagination.rs +++ b/packages/utils/src/pagination.rs @@ -36,7 +36,7 @@ pub fn calc_range_start_string(start_after: Option) -> Option> { #[cfg(test)] mod test { use super::*; - use cosmwasm_std::{testing::mock_dependencies, Order, StdError}; + use cosmwasm_std::{testing::mock_dependencies, Order}; use cw_storage_plus::{Bound, Map}; pub const HOLDERS: Map<&Addr, usize> = Map::new("some_data"); @@ -46,12 +46,6 @@ mod test { Addr::unchecked(format!("addr{:0>8}", i)) } - fn deser_holder_kv(holder_kv: Result<(Vec, usize), StdError>) -> (String, usize) { - let (k_bytes, v) = holder_kv.unwrap(); - let key = std::str::from_utf8(&k_bytes).unwrap().to_string(); - (key, v) - } - #[test] fn calc_range_start_works_as_expected() { let total_elements_count = 100; @@ -72,15 +66,15 @@ mod test { let start = calc_range_start(start_after).map(Bound::exclusive); - let holders: Vec<(String, usize)> = HOLDERS - .range_raw(&deps.storage, start, None, Order::Ascending) - .map(deser_holder_kv) + let holders = HOLDERS + .keys(&deps.storage, start, None, Order::Ascending) .take(LIMIT) - .collect(); + .collect::>>() + .unwrap(); for (i, holder) in holders.into_iter().enumerate() { let global_index = j * LIMIT + i; - assert_eq!(holder.0, addr_from_i(global_index)); + assert_eq!(holder, addr_from_i(global_index)); } } } @@ -101,15 +95,15 @@ mod test { let end = calc_range_end(end_before).map(Bound::exclusive); - let holders: Vec<(String, usize)> = HOLDERS - .range_raw(&deps.storage, None, end, Order::Descending) - .map(deser_holder_kv) + let holders = HOLDERS + .keys(&deps.storage, None, end, Order::Descending) .take(LIMIT) - .collect(); + .collect::>>() + .unwrap(); for (i, holder) in holders.into_iter().enumerate() { let global_index = total_elements_count - i - j * LIMIT - 1; - assert_eq!(holder.0, addr_from_i(global_index)); + assert_eq!(holder, addr_from_i(global_index)); } } } From 8f00fb31f749775ab6a677b30c76ea2285acd18e Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 20:53:24 +0100 Subject: [PATCH 36/47] Replace range_raw() plus manual deserialization by range() --- contracts/cw1155-base/src/contract.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index 74291b0f1..b83ca5d41 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -1,7 +1,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Order, Record, Response, StdResult, - SubMsg, Uint128, + to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Order, Response, StdResult, SubMsg, + Uint128, }; use cw_storage_plus::Bound; @@ -478,10 +478,10 @@ pub fn query(deps: Deps, env: Env, msg: Cw1155QueryMsg) -> StdResult { } } -fn parse_approval(item: StdResult>) -> StdResult { - item.and_then(|(k, expires)| { - let spender = String::from_utf8(k)?; - Ok(cw1155::Approval { spender, expires }) +fn build_approval(item: StdResult<(Addr, Expiration)>) -> StdResult { + item.map(|(addr, expires)| cw1155::Approval { + spender: addr.into(), + expires, }) } @@ -498,10 +498,10 @@ fn query_all_approvals( let operators = APPROVES .prefix(&owner) - .range_raw(deps.storage, start, None, Order::Ascending) + .range(deps.storage, start, None, Order::Ascending) .filter(|r| include_expired || r.is_err() || !r.as_ref().unwrap().1.is_expired(&env.block)) .take(limit) - .map(parse_approval) + .map(build_approval) .collect::>()?; Ok(ApprovedForAllResponse { operators }) } From 64f3a33f020170cede0ded3ddebbd34a3da7e2b1 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 20:53:58 +0100 Subject: [PATCH 37/47] Replace range_raw() plus manual deserialization by keys() --- contracts/cw1155-base/src/contract.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index b83ca5d41..e3195cff3 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -517,9 +517,8 @@ fn query_tokens( let tokens = BALANCES .prefix(&owner) - .range_raw(deps.storage, start, None, Order::Ascending) + .keys(deps.storage, start, None, Order::Ascending) .take(limit) - .map(|item| item.map(|(k, _)| String::from_utf8(k).unwrap())) .collect::>()?; Ok(TokensResponse { tokens }) } @@ -532,9 +531,8 @@ fn query_all_tokens( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); let tokens = TOKENS - .range_raw(deps.storage, start, None, Order::Ascending) + .keys(deps.storage, start, None, Order::Ascending) .take(limit) - .map(|item| item.map(|(k, _)| String::from_utf8(k).unwrap())) .collect::>()?; Ok(TokensResponse { tokens }) } From 3b4ba152bce41ba47ff4554d73fcded40a7f17ac Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 21:22:49 +0100 Subject: [PATCH 38/47] Replace range_raw() + deserialization by range() --- contracts/cw1-subkeys/src/contract.rs | 34 ++++++++++++--------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/contracts/cw1-subkeys/src/contract.rs b/contracts/cw1-subkeys/src/contract.rs index 84304be68..fca7ee1a4 100644 --- a/contracts/cw1-subkeys/src/contract.rs +++ b/contracts/cw1-subkeys/src/contract.rs @@ -409,8 +409,8 @@ pub fn query_all_allowances( // we use raw addresses here.... let start = start_after.map(Bound::exclusive); - let res: StdResult> = ALLOWANCES - .range_raw(deps.storage, start, None, Order::Ascending) + let allowances = ALLOWANCES + .range(deps.storage, start, None, Order::Ascending) .filter(|item| { if let Ok((_, allow)) = item { !allow.expires.is_expired(&env.block) @@ -420,16 +420,14 @@ pub fn query_all_allowances( }) .take(limit) .map(|item| { - item.and_then(|(k, allow)| { - Ok(AllowanceInfo { - spender: String::from_utf8(k)?, - balance: allow.balance, - expires: allow.expires, - }) + item.map(|(addr, allow)| AllowanceInfo { + spender: addr.into(), + balance: allow.balance, + expires: allow.expires, }) }) - .collect(); - Ok(AllAllowancesResponse { allowances: res? }) + .collect::>>()?; + Ok(AllAllowancesResponse { allowances }) } // return a list of all permissions here @@ -441,19 +439,17 @@ pub fn query_all_permissions( let limit = calc_limit(limit); let start = start_after.map(Bound::exclusive); - let res: StdResult> = PERMISSIONS - .range_raw(deps.storage, start, None, Order::Ascending) + let permissions = PERMISSIONS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - item.and_then(|(k, perm)| { - Ok(PermissionsInfo { - spender: String::from_utf8(k)?, - permissions: perm, - }) + item.map(|(addr, perm)| PermissionsInfo { + spender: addr.into(), + permissions: perm, }) }) - .collect(); - Ok(AllPermissionsResponse { permissions: res? }) + .collect::>>()?; + Ok(AllPermissionsResponse { permissions }) } // Migrate contract if version is lower than current version From d0d7c598fe460decd1aa1fd3d7c1f7299c80e0fc Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 21:33:41 +0100 Subject: [PATCH 39/47] Replace keys_raw() + deserialization by keys() --- contracts/cw20-atomic-swap/src/state.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/cw20-atomic-swap/src/state.rs b/contracts/cw20-atomic-swap/src/state.rs index 7df449e9d..0a1202630 100644 --- a/contracts/cw20-atomic-swap/src/state.rs +++ b/contracts/cw20-atomic-swap/src/state.rs @@ -1,7 +1,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use cosmwasm_std::{Addr, Binary, BlockInfo, Order, StdError, StdResult, Storage}; +use cosmwasm_std::{Addr, Binary, BlockInfo, Order, StdResult, Storage}; use cw_storage_plus::{Bound, Map}; use cw20::{Balance, Expiration}; @@ -32,9 +32,8 @@ pub fn all_swap_ids( limit: usize, ) -> StdResult> { SWAPS - .keys_raw(storage, start, None, Order::Ascending) + .keys(storage, start, None, Order::Ascending) .take(limit) - .map(|k| String::from_utf8(k).map_err(|_| StdError::invalid_utf8("Parsing swap id"))) .collect() } From 3c78f51601c1e89559f3de239a4cc10026ff7644 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 21:46:18 +0100 Subject: [PATCH 40/47] Replace range_raw() + deserialization by range() --- contracts/cw20-base/src/enumerable.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index 7b6c526c8..d93903536 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -18,22 +18,19 @@ pub fn query_all_allowances( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); - let allowances: StdResult> = ALLOWANCES + let allowances = ALLOWANCES .prefix(&owner_addr) - .range_raw(deps.storage, start, None, Order::Ascending) + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (k, v) = item?; - Ok(AllowanceInfo { - spender: String::from_utf8(k)?, - allowance: v.allowance, - expires: v.expires, + item.map(|(addr, allow)| AllowanceInfo { + spender: addr.into(), + allowance: allow.allowance, + expires: allow.expires, }) }) - .collect(); - Ok(AllAllowancesResponse { - allowances: allowances?, - }) + .collect::>()?; + Ok(AllAllowancesResponse { allowances }) } pub fn query_all_accounts( From c5eba5bf0464a338764bc1454a5da57c23807b13 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 21:47:38 +0100 Subject: [PATCH 41/47] Replace keys_raw() + deserialization by keys() --- contracts/cw20-base/src/enumerable.rs | 12 +++++------- contracts/cw20-escrow/src/state.rs | 5 ++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/contracts/cw20-base/src/enumerable.rs b/contracts/cw20-base/src/enumerable.rs index d93903536..cb7dc74fc 100644 --- a/contracts/cw20-base/src/enumerable.rs +++ b/contracts/cw20-base/src/enumerable.rs @@ -41,15 +41,13 @@ pub fn query_all_accounts( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); - let accounts: Result, _> = BALANCES - .keys_raw(deps.storage, start, None, Order::Ascending) - .map(String::from_utf8) + let accounts = BALANCES + .keys(deps.storage, start, None, Order::Ascending) .take(limit) - .collect(); + .map(|item| item.map(Into::into)) + .collect::>()?; - Ok(AllAccountsResponse { - accounts: accounts?, - }) + Ok(AllAccountsResponse { accounts }) } #[cfg(test)] diff --git a/contracts/cw20-escrow/src/state.rs b/contracts/cw20-escrow/src/state.rs index c09dcd3e2..3940d6160 100644 --- a/contracts/cw20-escrow/src/state.rs +++ b/contracts/cw20-escrow/src/state.rs @@ -1,7 +1,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use cosmwasm_std::{Addr, Coin, Env, Order, StdError, StdResult, Storage, Timestamp}; +use cosmwasm_std::{Addr, Coin, Env, Order, StdResult, Storage, Timestamp}; use cw_storage_plus::Map; use cw20::{Balance, Cw20CoinVerified}; @@ -95,8 +95,7 @@ pub const ESCROWS: Map<&str, Escrow> = Map::new("escrow"); /// This returns the list of ids for all registered escrows pub fn all_escrow_ids(storage: &dyn Storage) -> StdResult> { ESCROWS - .keys_raw(storage, None, None, Order::Ascending) - .map(|k| String::from_utf8(k).map_err(|_| StdError::invalid_utf8("parsing escrow key"))) + .keys(storage, None, None, Order::Ascending) .collect() } From 5f9da6bf5faa190d2c9311c98e37899713fdede9 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 22:04:17 +0100 Subject: [PATCH 42/47] Replace range_raw() + deserialization by range() Refactor raw_range iterator --- contracts/cw20-ics20/src/contract.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index 03a806102..132c08dd6 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -151,32 +151,30 @@ fn query_port(deps: Deps) -> StdResult { } fn query_list(deps: Deps) -> StdResult { - let channels: StdResult> = CHANNEL_INFO + let channels = CHANNEL_INFO .range_raw(deps.storage, None, None, Order::Ascending) .map(|r| r.map(|(_, v)| v)) - .collect(); - Ok(ListChannelsResponse { - channels: channels?, - }) + .collect::>()?; + Ok(ListChannelsResponse { channels }) } // make public for ibc tests pub fn query_channel(deps: Deps, id: String) -> StdResult { let info = CHANNEL_INFO.load(deps.storage, &id)?; // this returns Vec<(outstanding, total)> - let state: StdResult> = CHANNEL_STATE + let state = CHANNEL_STATE .prefix(&id) - .range_raw(deps.storage, None, None, Order::Ascending) + .range(deps.storage, None, None, Order::Ascending) .map(|r| { - let (k, v) = r?; - let denom = String::from_utf8(k)?; - let outstanding = Amount::from_parts(denom.clone(), v.outstanding); - let total = Amount::from_parts(denom, v.total_sent); - Ok((outstanding, total)) + r.map(|(denom, v)| { + let outstanding = Amount::from_parts(denom.clone(), v.outstanding); + let total = Amount::from_parts(denom, v.total_sent); + (outstanding, total) + }) }) - .collect(); + .collect::>>()?; // we want (Vec, Vec) - let (balances, total_sent) = state?.into_iter().unzip(); + let (balances, total_sent) = state.into_iter().unzip(); Ok(ChannelResponse { info, From f04f1f3b519a6774cddcf6fb88f2183ccb4992e9 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Sat, 11 Dec 2021 22:56:59 +0100 Subject: [PATCH 43/47] Replace range_raw() + deserialization by range() --- contracts/cw3-fixed-multisig/src/contract.rs | 69 ++++++++++---------- contracts/cw3-flex-multisig/src/contract.rs | 52 +++++++-------- contracts/cw4-group/src/contract.rs | 13 ++-- contracts/cw4-stake/src/contract.rs | 13 ++-- 4 files changed, 70 insertions(+), 77 deletions(-) diff --git a/contracts/cw3-fixed-multisig/src/contract.rs b/contracts/cw3-fixed-multisig/src/contract.rs index 48a600834..2f2ef70d5 100644 --- a/contracts/cw3-fixed-multisig/src/contract.rs +++ b/contracts/cw3-fixed-multisig/src/contract.rs @@ -17,9 +17,7 @@ use utils::Expiration; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::state::{ - next_id, parse_id, Ballot, Config, Proposal, BALLOTS, CONFIG, PROPOSALS, VOTERS, -}; +use crate::state::{next_id, Ballot, Config, Proposal, BALLOTS, CONFIG, PROPOSALS, VOTERS}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:cw3-fixed-multisig"; @@ -315,13 +313,13 @@ fn list_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive_int); - let props: StdResult> = PROPOSALS - .range_raw(deps.storage, start, None, Order::Ascending) + let proposals = PROPOSALS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|p| map_proposal(&env.block, &threshold, p)) - .collect(); + .collect::>()?; - Ok(ProposalListResponse { proposals: props? }) + Ok(ProposalListResponse { proposals }) } fn reverse_proposals( @@ -338,30 +336,31 @@ fn reverse_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let end = start_before.map(Bound::exclusive_int); - let props: StdResult> = PROPOSALS - .range_raw(deps.storage, None, end, Order::Descending) + let proposals = PROPOSALS + .range(deps.storage, None, end, Order::Descending) .take(limit) .map(|p| map_proposal(&env.block, &threshold, p)) - .collect(); + .collect::>()?; - Ok(ProposalListResponse { proposals: props? }) + Ok(ProposalListResponse { proposals }) } fn map_proposal( block: &BlockInfo, threshold: &ThresholdResponse, - item: StdResult<(Vec, Proposal)>, + item: StdResult<(u64, Proposal)>, ) -> StdResult { - let (key, prop) = item?; - let status = prop.current_status(block); - Ok(ProposalResponse { - id: parse_id(&key)?, - title: prop.title, - description: prop.description, - msgs: prop.msgs, - status, - expires: prop.expires, - threshold: threshold.clone(), + item.map(|(id, prop)| { + let status = prop.current_status(block); + ProposalResponse { + id, + title: prop.title, + description: prop.description, + msgs: prop.msgs, + status, + expires: prop.expires, + threshold: threshold.clone(), + } }) } @@ -385,21 +384,20 @@ fn list_votes( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); - let votes: StdResult> = BALLOTS + let votes = BALLOTS .prefix(proposal_id) - .range_raw(deps.storage, start, None, Order::Ascending) + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (key, ballot) = item?; - Ok(VoteInfo { - voter: String::from_utf8(key)?, + item.map(|(addr, ballot)| VoteInfo { + voter: addr.into(), vote: ballot.vote, weight: ballot.weight, }) }) - .collect(); + .collect::>()?; - Ok(VoteListResponse { votes: votes? }) + Ok(VoteListResponse { votes }) } fn query_voter(deps: Deps, voter: String) -> StdResult { @@ -416,19 +414,18 @@ fn list_voters( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive); - let voters: StdResult> = VOTERS - .range_raw(deps.storage, start, None, Order::Ascending) + let voters = VOTERS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (key, weight) = item?; - Ok(VoterDetail { - addr: String::from_utf8(key)?, + item.map(|(addr, weight)| VoterDetail { + addr: addr.into(), weight, }) }) - .collect(); + .collect::>()?; - Ok(VoterListResponse { voters: voters? }) + Ok(VoterListResponse { voters }) } #[cfg(test)] diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index c7293d99c..38169b6b5 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -18,9 +18,7 @@ use utils::{maybe_addr, Expiration}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; -use crate::state::{ - next_id, parse_id, Ballot, Config, Proposal, Votes, BALLOTS, CONFIG, PROPOSALS, -}; +use crate::state::{next_id, Ballot, Config, Proposal, Votes, BALLOTS, CONFIG, PROPOSALS}; // version info for migration info const CONTRACT_NAME: &str = "crates.io:cw3-flex-multisig"; @@ -317,13 +315,13 @@ fn list_proposals( ) -> StdResult { let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let start = start_after.map(Bound::exclusive_int); - let props: StdResult> = PROPOSALS - .range_raw(deps.storage, start, None, Order::Ascending) + let proposals = PROPOSALS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|p| map_proposal(&env.block, p)) - .collect(); + .collect::>()?; - Ok(ProposalListResponse { proposals: props? }) + Ok(ProposalListResponse { proposals }) } fn reverse_proposals( @@ -335,7 +333,7 @@ fn reverse_proposals( let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; let end = start_before.map(Bound::exclusive_int); let props: StdResult> = PROPOSALS - .range_raw(deps.storage, None, end, Order::Descending) + .range(deps.storage, None, end, Order::Descending) .take(limit) .map(|p| map_proposal(&env.block, p)) .collect(); @@ -345,19 +343,20 @@ fn reverse_proposals( fn map_proposal( block: &BlockInfo, - item: StdResult<(Vec, Proposal)>, + item: StdResult<(u64, Proposal)>, ) -> StdResult { - let (key, prop) = item?; - let status = prop.current_status(block); - let threshold = prop.threshold.to_response(prop.total_weight); - Ok(ProposalResponse { - id: parse_id(&key)?, - title: prop.title, - description: prop.description, - msgs: prop.msgs, - status, - expires: prop.expires, - threshold, + item.map(|(id, prop)| { + let status = prop.current_status(block); + let threshold = prop.threshold.to_response(prop.total_weight); + ProposalResponse { + id, + title: prop.title, + description: prop.description, + msgs: prop.msgs, + status, + expires: prop.expires, + threshold, + } }) } @@ -382,21 +381,20 @@ fn list_votes( let addr = maybe_addr(deps.api, start_after)?; let start = addr.map(|addr| Bound::exclusive(addr.as_ref())); - let votes: StdResult> = BALLOTS + let votes = BALLOTS .prefix(proposal_id) - .range_raw(deps.storage, start, None, Order::Ascending) + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (voter, ballot) = item?; - Ok(VoteInfo { - voter: String::from_utf8(voter)?, + item.map(|(addr, ballot)| VoteInfo { + voter: addr.into(), vote: ballot.vote, weight: ballot.weight, }) }) - .collect(); + .collect::>()?; - Ok(VoteListResponse { votes: votes? }) + Ok(VoteListResponse { votes }) } fn query_voter(deps: Deps, voter: String) -> StdResult { diff --git a/contracts/cw4-group/src/contract.rs b/contracts/cw4-group/src/contract.rs index e0a34d3f1..e41e9d9f6 100644 --- a/contracts/cw4-group/src/contract.rs +++ b/contracts/cw4-group/src/contract.rs @@ -192,19 +192,18 @@ fn list_members( let addr = maybe_addr(deps.api, start_after)?; let start = addr.map(|addr| Bound::exclusive(addr.to_string())); - let members: StdResult> = MEMBERS - .range_raw(deps.storage, start, None, Order::Ascending) + let members = MEMBERS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (key, weight) = item?; - Ok(Member { - addr: String::from_utf8(key)?, + item.map(|(addr, weight)| Member { + addr: addr.into(), weight, }) }) - .collect(); + .collect::>()?; - Ok(MemberListResponse { members: members? }) + Ok(MemberListResponse { members }) } #[cfg(test)] diff --git a/contracts/cw4-stake/src/contract.rs b/contracts/cw4-stake/src/contract.rs index 20aa3b6f2..635a20080 100644 --- a/contracts/cw4-stake/src/contract.rs +++ b/contracts/cw4-stake/src/contract.rs @@ -341,19 +341,18 @@ fn list_members( let addr = maybe_addr(deps.api, start_after)?; let start = addr.map(|addr| Bound::exclusive(addr.as_ref())); - let members: StdResult> = MEMBERS - .range_raw(deps.storage, start, None, Order::Ascending) + let members = MEMBERS + .range(deps.storage, start, None, Order::Ascending) .take(limit) .map(|item| { - let (key, weight) = item?; - Ok(Member { - addr: String::from_utf8(key)?, + item.map(|(addr, weight)| Member { + addr: addr.into(), weight, }) }) - .collect(); + .collect::>()?; - Ok(MemberListResponse { members: members? }) + Ok(MemberListResponse { members }) } #[cfg(test)] From ae2537cf60e5b15321cdeeaaba08f5bbe3425365 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 13 Dec 2021 07:59:20 +0100 Subject: [PATCH 44/47] Update test cases/comments in Map for clarity --- packages/storage-plus/src/map.rs | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index c7f7fc02c..320c7a64c 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -124,7 +124,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) #[cfg(feature = "iterator")] impl<'a, K, T> Map<'a, K, T> where @@ -133,8 +133,8 @@ where // Other cases need to call prefix() first K: PrimaryKey<'a>, { - /// While `range` over a `prefix` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the `Prefix` + /// While `range_raw` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range_raw` accepts bounds for the lowest and highest elements of the `Prefix` /// itself, and iterates over those (inclusively or exclusively, depending on `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. @@ -395,7 +395,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_simple_key() { + fn range_raw_simple_key() { let mut store = MockStorage::new(); // save and load on two keys @@ -457,7 +457,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_simple_string_key() { + fn range_simple_string_key() { let mut store = MockStorage::new(); // save and load on two keys @@ -517,7 +517,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_simple_integer_key() { + fn range_simple_integer_key() { let mut store = MockStorage::new(); // save and load on two keys @@ -570,7 +570,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_composite_key() { + fn range_raw_composite_key() { let mut store = MockStorage::new(); // save and load on three keys, one under different owner @@ -614,7 +614,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_composite_key() { + fn range_composite_key() { let mut store = MockStorage::new(); // save and load on three keys, one under different owner @@ -643,7 +643,7 @@ mod test { ] ); - // let's try to iterate over a prefix_de + // let's try to iterate over a prefix let all: StdResult> = ALLOWANCE .prefix(b"owner") .range(&store, None, None, Order::Ascending) @@ -658,7 +658,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_triple_key() { + fn range_raw_triple_key() { let mut store = MockStorage::new(); // save and load on three keys, one under different owner @@ -725,7 +725,7 @@ mod test { .collect(); let all = all.unwrap(); assert_eq!(3, all.len()); - // Use range_de() if you want key deserialization + // Use range() if you want key deserialization assert_eq!( all, vec![ @@ -738,7 +738,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_triple_key() { + fn range_triple_key() { let mut store = MockStorage::new(); // save and load on three keys, one under different owner @@ -769,7 +769,7 @@ mod test { ] ); - // let's iterate over a sub_prefix_de + // let's iterate over a sub_prefix let all: StdResult> = TRIPLE .sub_prefix(b"owner") .range(&store, None, None, Order::Ascending) @@ -785,7 +785,7 @@ mod test { ] ); - // let's iterate over a prefix_de + // let's iterate over a prefix let all: StdResult> = TRIPLE .prefix((b"owner", 9)) .range(&store, None, None, Order::Ascending) @@ -931,7 +931,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn readme_with_range() -> StdResult<()> { + fn readme_with_range_raw() -> StdResult<()> { let mut store = MockStorage::new(); // save and load on two keys @@ -998,7 +998,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefixed_range_works() { + fn prefixed_range_raw_works() { // this is designed to look as much like a secondary index as possible // we want to query over a range of u32 for the first key and all subkeys const AGES: Map<(u32, Vec), u64> = Map::new("ages"); @@ -1084,7 +1084,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefixed_range_de_works() { + fn prefixed_range_works() { // this is designed to look as much like a secondary index as possible // we want to query over a range of u32 for the first key and all subkeys const AGES: Map<(u32, &str), u64> = Map::new("ages"); From 8a0365f5f5a6b8c6eb7904e794910280dadade62 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 13 Dec 2021 08:09:52 +0100 Subject: [PATCH 45/47] Update test cases/comments in SnapshotMap --- packages/storage-plus/src/snapshot/map.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/storage-plus/src/snapshot/map.rs b/packages/storage-plus/src/snapshot/map.rs index 030e08937..ef1d572b4 100644 --- a/packages/storage-plus/src/snapshot/map.rs +++ b/packages/storage-plus/src/snapshot/map.rs @@ -156,7 +156,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) impl<'a, K, T> SnapshotMap<'a, K, T> where T: Serialize + DeserializeOwned + Clone, @@ -333,7 +333,7 @@ mod tests { const VALUES_START_5: &[(&str, Option)] = &[("A", Some(8)), ("B", None), ("C", Some(13)), ("D", None)]; - // Same as `init_data`, but we have a composite key for testing range_de. + // Same as `init_data`, but we have a composite key for testing range. fn init_data_composite_key(map: &TestMapCompositeKey, storage: &mut dyn Storage) { map.save(storage, ("A", "B"), &5, 1).unwrap(); map.save(storage, ("B", "A"), &7, 2).unwrap(); @@ -460,7 +460,7 @@ mod tests { #[test] #[cfg(feature = "iterator")] - fn range_de_simple_string_key() { + fn range_simple_string_key() { use cosmwasm_std::Order; let mut store = MockStorage::new(); @@ -501,7 +501,7 @@ mod tests { #[test] #[cfg(feature = "iterator")] - fn range_de_composite_key() { + fn range_composite_key() { use cosmwasm_std::Order; let mut store = MockStorage::new(); @@ -524,7 +524,7 @@ mod tests { #[test] #[cfg(feature = "iterator")] - fn prefix_range_de_composite_key() { + fn prefix_range_composite_key() { use cosmwasm_std::Order; let mut store = MockStorage::new(); @@ -546,7 +546,7 @@ mod tests { #[test] #[cfg(feature = "iterator")] - fn prefix_de_composite_key() { + fn prefix_composite_key() { use cosmwasm_std::Order; let mut store = MockStorage::new(); @@ -564,7 +564,7 @@ mod tests { #[test] #[cfg(feature = "iterator")] - fn sub_prefix_de_composite_key() { + fn sub_prefix_composite_key() { use cosmwasm_std::Order; let mut store = MockStorage::new(); @@ -572,7 +572,7 @@ mod tests { // Let's sub-prefix and iterate. // This is similar to calling range() directly, but added here for completeness / - // sub_prefix_de type checks + // sub_prefix type checks let all: StdResult> = EVERY_COMPOSITE_KEY .sub_prefix(()) .range(&store, None, None, Order::Ascending) From 200948f89b29f93e7d935202704dc8e7fa53dd8d Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 13 Dec 2021 08:11:02 +0100 Subject: [PATCH 46/47] Adjust indexes comments --- packages/storage-plus/src/indexes/multi.rs | 6 +++--- packages/storage-plus/src/indexes/unique.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/storage-plus/src/indexes/multi.rs b/packages/storage-plus/src/indexes/multi.rs index 499e7bb44..91a4f29c7 100644 --- a/packages/storage-plus/src/indexes/multi.rs +++ b/packages/storage-plus/src/indexes/multi.rs @@ -187,7 +187,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) impl<'a, IK, T, PK> MultiIndex<'a, IK, T, PK> where T: Serialize + DeserializeOwned + Clone, @@ -218,8 +218,8 @@ where self.no_prefix_raw().keys_raw(store, min, max, order) } - /// While `range` over a `prefix` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the + /// While `range_raw` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range_raw` accepts bounds for the lowest and highest elements of the /// `Prefix` itself, and iterates over those (inclusively or exclusively, depending on /// `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't diff --git a/packages/storage-plus/src/indexes/unique.rs b/packages/storage-plus/src/indexes/unique.rs index 06c266fa1..6f729db10 100644 --- a/packages/storage-plus/src/indexes/unique.rs +++ b/packages/storage-plus/src/indexes/unique.rs @@ -132,7 +132,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) impl<'a, IK, T, PK> UniqueIndex<'a, IK, T, PK> where T: Serialize + DeserializeOwned + Clone, From 4181f547282ed3b1cc51ad9b2b3d449b3e81426a Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Mon, 13 Dec 2021 08:31:25 +0100 Subject: [PATCH 47/47] Update test cases/comments in indexed maps --- packages/storage-plus/src/indexed_map.rs | 42 +++++++++---------- packages/storage-plus/src/indexed_snapshot.rs | 36 ++++++++-------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index b67dadb9a..d9a7df53c 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -135,7 +135,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) impl<'a, K, T, I> IndexedMap<'a, K, T, I> where K: PrimaryKey<'a>, @@ -175,8 +175,8 @@ where T: Serialize + DeserializeOwned + Clone, I: IndexList, { - /// While `range` over a `prefix` fixes the prefix to one element and iterates over the - /// remaining, `prefix_range` accepts bounds for the lowest and highest elements of the `Prefix` + /// While `range_raw` over a `prefix` fixes the prefix to one element and iterates over the + /// remaining, `prefix_range_raw` accepts bounds for the lowest and highest elements of the `Prefix` /// itself, and iterates over those (inclusively or exclusively, depending on `PrefixBound`). /// There are some issues that distinguish these two, and blindly casting to `Vec` doesn't /// solve them. @@ -520,7 +520,7 @@ mod test { } #[test] - fn range_simple_key_by_multi_index() { + fn range_raw_simple_key_by_multi_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -576,7 +576,7 @@ mod test { } #[test] - fn range_de_simple_key_by_multi_index() { + fn range_simple_key_by_multi_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -632,7 +632,7 @@ mod test { } #[test] - fn range_composite_key_by_multi_index() { + fn range_raw_composite_key_by_multi_index() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -693,7 +693,7 @@ mod test { } #[test] - fn range_de_composite_key_by_multi_index() { + fn range_composite_key_by_multi_index() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -861,7 +861,7 @@ mod test { } #[test] - fn range_simple_key_by_unique_index() { + fn range_raw_simple_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -894,7 +894,7 @@ mod test { } #[test] - fn range_de_simple_key_by_unique_index() { + fn range_simple_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -927,7 +927,7 @@ mod test { } #[test] - fn range_composite_key_by_unique_index() { + fn range_raw_composite_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -956,7 +956,7 @@ mod test { } #[test] - fn range_de_composite_key_by_unique_index() { + fn range_composite_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_map(); @@ -986,7 +986,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_simple_string_key() { + fn range_simple_string_key() { let mut store = MockStorage::new(); let map = build_map(); @@ -1029,7 +1029,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_de_simple_string_key() { + fn prefix_simple_string_key() { let mut store = MockStorage::new(); let map = build_map(); @@ -1037,7 +1037,7 @@ mod test { let (pks, datas) = save_data(&mut store, &map); // Let's prefix and iterate. - // This is similar to calling range() directly, but added here for completeness / prefix_de + // This is similar to calling range() directly, but added here for completeness / prefix // type checks let all: StdResult> = map .prefix(()) @@ -1056,7 +1056,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_de_composite_key() { + fn prefix_composite_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -1111,7 +1111,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_de_triple_key() { + fn prefix_triple_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -1163,7 +1163,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn sub_prefix_de_triple_key() { + fn sub_prefix_triple_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -1221,7 +1221,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_range_de_simple_key() { + fn prefix_range_simple_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -1262,7 +1262,7 @@ mod test { let pk4 = ("3", "5630"); map.save(&mut store, pk4, &data4).unwrap(); - // let's try to iterate! + // let's prefix-range and iterate let result: StdResult> = map .prefix_range( &store, @@ -1281,7 +1281,7 @@ mod test { ] ); - // let's try to iterate over a range + // let's try to iterate over a more restrictive prefix-range! let result: StdResult> = map .prefix_range( &store, @@ -1302,7 +1302,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_range_de_triple_key() { + fn prefix_range_triple_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { diff --git a/packages/storage-plus/src/indexed_snapshot.rs b/packages/storage-plus/src/indexed_snapshot.rs index 2b7914186..7b2eb7b82 100644 --- a/packages/storage-plus/src/indexed_snapshot.rs +++ b/packages/storage-plus/src/indexed_snapshot.rs @@ -180,7 +180,7 @@ where } } -// short-cut for simple keys, rather than .prefix(()).range(...) +// short-cut for simple keys, rather than .prefix(()).range_raw(...) impl<'a, K, T, I> IndexedSnapshotMap<'a, K, T, I> where K: PrimaryKey<'a> + Prefixer<'a> + KeyDeserialize, @@ -488,7 +488,7 @@ mod test { } #[test] - fn range_simple_key_by_multi_index() { + fn range_raw_simple_key_by_multi_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); let mut height = 1; @@ -548,7 +548,7 @@ mod test { } #[test] - fn range_de_simple_key_by_multi_index() { + fn range_simple_key_by_multi_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); let mut height = 1; @@ -608,7 +608,7 @@ mod test { } #[test] - fn range_composite_key_by_multi_index() { + fn range_raw_composite_key_by_multi_index() { let mut store = MockStorage::new(); let mut height = 2; @@ -674,7 +674,7 @@ mod test { } #[test] - fn range_de_composite_key_by_multi_index() { + fn range_composite_key_by_multi_index() { let mut store = MockStorage::new(); let mut height = 2; @@ -853,7 +853,7 @@ mod test { } #[test] - fn range_simple_key_by_unique_index() { + fn range_raw_simple_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -884,7 +884,7 @@ mod test { } #[test] - fn range_de_simple_key_by_unique_index() { + fn range_simple_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -915,7 +915,7 @@ mod test { } #[test] - fn range_composite_key_by_unique_index() { + fn range_raw_composite_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -944,7 +944,7 @@ mod test { } #[test] - fn range_de_composite_key_by_unique_index() { + fn range_composite_key_by_unique_index() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -974,7 +974,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn range_de_simple_string_key() { + fn range_simple_string_key() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -1017,7 +1017,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_de_simple_string_key() { + fn prefix_simple_string_key() { let mut store = MockStorage::new(); let map = build_snapshot_map(); @@ -1025,7 +1025,7 @@ mod test { let (pks, datas) = save_data(&mut store, &map); // Let's prefix and iterate. - // This is similar to calling range() directly, but added here for completeness / prefix_de + // This is similar to calling range() directly, but added here for completeness / prefix // type checks let all: StdResult> = map .prefix(()) @@ -1044,15 +1044,15 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn sub_prefix_de_simple_string_key() { + fn sub_prefix_simple_string_key() { let mut store = MockStorage::new(); let map = build_snapshot_map(); // save data let (pks, datas) = save_data(&mut store, &map); - // Let's prefix and iterate. - // This is similar to calling range() directly, but added here for completeness / sub_prefix_de + // Let's sub-prefix and iterate. + // This is similar to calling range() directly, but added here for completeness / sub_prefix // type checks let all: StdResult> = map .sub_prefix(()) @@ -1071,7 +1071,7 @@ mod test { #[test] #[cfg(feature = "iterator")] - fn prefix_range_de_simple_key() { + fn prefix_range_simple_key() { let mut store = MockStorage::new(); let indexes = DataCompositeMultiIndex { @@ -1113,7 +1113,7 @@ mod test { let pk4: (&str, &str) = ("3", "5630"); map.save(&mut store, pk4, &data4, 1).unwrap(); - // let's try to iterate! + // let's prefix-range and iterate let result: StdResult> = map .prefix_range( &store, @@ -1132,7 +1132,7 @@ mod test { ] ); - // let's try to iterate over a range + // let's try to iterate over a more restrictive prefix-range! let result: StdResult> = map .prefix_range( &store,