From 137f32692f141d7b39dab55761a98a91fdc6d505 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 2 Apr 2021 10:11:45 +0800 Subject: [PATCH] rename KV -> Pair --- contracts/cw1155-base/src/contract.rs | 6 ++-- contracts/cw721-base/src/contract.rs | 4 +-- packages/multi-test/src/transactions.rs | 40 +++++++++++------------ packages/storage-plus/src/indexed_map.rs | 2 +- packages/storage-plus/src/indexes.rs | 16 ++++----- packages/storage-plus/src/iter_helpers.rs | 12 +++---- packages/storage-plus/src/map.rs | 2 +- packages/storage-plus/src/prefix.rs | 8 ++--- packages/storage-plus/src/snapshot.rs | 2 +- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/contracts/cw1155-base/src/contract.rs b/contracts/cw1155-base/src/contract.rs index a4ee7ab66..f03cfee7d 100644 --- a/contracts/cw1155-base/src/contract.rs +++ b/contracts/cw1155-base/src/contract.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - to_binary, Api, Binary, Deps, DepsMut, Env, HumanAddr, MessageInfo, Order, Response, StdResult, - Uint128, KV, + to_binary, Api, Binary, Deps, DepsMut, Env, HumanAddr, MessageInfo, Order, Pair, Response, + StdResult, Uint128, }; use cw_storage_plus::Bound; @@ -459,7 +459,7 @@ pub fn query(deps: Deps, env: Env, msg: Cw1155QueryMsg) -> StdResult { } } -fn parse_approval(api: &dyn Api, item: StdResult>) -> StdResult { +fn parse_approval(api: &dyn Api, item: StdResult>) -> StdResult { item.and_then(|(k, expires)| { let spender = api.human_address(&k.into())?; Ok(cw1155::Approval { spender, expires }) diff --git a/contracts/cw721-base/src/contract.rs b/contracts/cw721-base/src/contract.rs index 26b04ec2f..66a8b47e2 100644 --- a/contracts/cw721-base/src/contract.rs +++ b/contracts/cw721-base/src/contract.rs @@ -2,7 +2,7 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ attr, to_binary, Api, Binary, BlockInfo, Deps, DepsMut, Env, HumanAddr, MessageInfo, Order, - Response, StdError, StdResult, KV, + Pair, Response, StdError, StdResult, }; use cw0::maybe_canonical; @@ -497,7 +497,7 @@ fn query_all_approvals( Ok(ApprovedForAllResponse { operators: res? }) } -fn parse_approval(api: &dyn Api, item: StdResult>) -> StdResult { +fn parse_approval(api: &dyn Api, item: StdResult>) -> StdResult { item.and_then(|(k, expires)| { let spender = api.human_address(&k.into())?; Ok(cw721::Approval { spender, expires }) diff --git a/packages/multi-test/src/transactions.rs b/packages/multi-test/src/transactions.rs index 5a6b282f2..f87316765 100644 --- a/packages/multi-test/src/transactions.rs +++ b/packages/multi-test/src/transactions.rs @@ -10,7 +10,7 @@ use std::ops::{Bound, RangeBounds}; use cosmwasm_std::Storage; #[cfg(feature = "iterator")] -use cosmwasm_std::{Order, KV}; +use cosmwasm_std::{Order, Pair}; #[cfg(feature = "iterator")] /// The BTreeMap specific key-value pair reference type, as returned by BTreeMap, T>::range. @@ -79,7 +79,7 @@ impl<'a> Storage for StorageTransaction<'a> { start: Option<&[u8]>, end: Option<&[u8]>, order: Order, - ) -> Box + 'b> { + ) -> Box + 'b> { let bounds = range_bounds(start, end); // BTreeMap.range panics if range is start > end. @@ -172,7 +172,7 @@ enum Delta { struct MergeOverlay<'a, L, R> where L: Iterator>, - R: Iterator, + R: Iterator, { left: Peekable, right: Peekable, @@ -183,7 +183,7 @@ where impl<'a, L, R> MergeOverlay<'a, L, R> where L: Iterator>, - R: Iterator, + R: Iterator, { fn new(left: L, right: R, order: Order) -> Self { MergeOverlay { @@ -193,7 +193,7 @@ where } } - fn pick_match(&mut self, lkey: Vec, rkey: Vec) -> Option { + fn pick_match(&mut self, lkey: Vec, rkey: Vec) -> Option { // compare keys - result is such that Ordering::Less => return left side let order = match self.order { Order::Ascending => lkey.cmp(&rkey), @@ -213,7 +213,7 @@ where } /// take_left must only be called when we know self.left.next() will return Some - fn take_left(&mut self) -> Option { + fn take_left(&mut self) -> Option { let (lkey, lval) = self.left.next().unwrap(); match lval { Delta::Set { value } => Some((lkey.clone(), value.clone())), @@ -226,9 +226,9 @@ where impl<'a, L, R> Iterator for MergeOverlay<'a, L, R> where L: Iterator>, - R: Iterator, + R: Iterator, { - type Item = KV; + type Item = Pair; fn next(&mut self) -> Option { let (left, right) = (self.left.peek(), self.right.peek()); @@ -352,7 +352,7 @@ mod test { // unbounded { let iter = store.range(None, None, Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -366,7 +366,7 @@ mod test { // unbounded (descending) { let iter = store.range(None, None, Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -380,14 +380,14 @@ mod test { // bounded { let iter = store.range(Some(b"f"), Some(b"n"), Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![(b"foo".to_vec(), b"bar".to_vec())]); } // bounded (descending) { let iter = store.range(Some(b"air"), Some(b"loop"), Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -400,35 +400,35 @@ mod test { // bounded empty [a, a) { let iter = store.range(Some(b"foo"), Some(b"foo"), Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![]); } // bounded empty [a, a) (descending) { let iter = store.range(Some(b"foo"), Some(b"foo"), Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![]); } // bounded empty [a, b) with b < a { let iter = store.range(Some(b"z"), Some(b"a"), Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![]); } // bounded empty [a, b) with b < a (descending) { let iter = store.range(Some(b"z"), Some(b"a"), Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![]); } // right unbounded { let iter = store.range(Some(b"f"), None, Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -441,7 +441,7 @@ mod test { // right unbounded (descending) { let iter = store.range(Some(b"f"), None, Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -454,14 +454,14 @@ mod test { // left unbounded { let iter = store.range(None, Some(b"f"), Order::Ascending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!(elements, vec![(b"ant".to_vec(), b"hill".to_vec()),]); } // left unbounded (descending) { let iter = store.range(None, Some(b"no"), Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index e7f5f30aa..a7744164a 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -149,7 +149,7 @@ where min: Option, max: Option, order: cosmwasm_std::Order, - ) -> Box>> + 'c> + ) -> Box>> + 'c> where T: 'c, { diff --git a/packages/storage-plus/src/indexes.rs b/packages/storage-plus/src/indexes.rs index 5491f4938..219bc3ad9 100644 --- a/packages/storage-plus/src/indexes.rs +++ b/packages/storage-plus/src/indexes.rs @@ -4,7 +4,7 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use cosmwasm_std::{from_slice, Binary, Order, StdError, StdResult, Storage, KV}; +use cosmwasm_std::{from_slice, Binary, Order, Pair, StdError, StdResult, Storage}; use crate::helpers::namespaces_with_key; use crate::keys::EmptyPrefix; @@ -77,8 +77,8 @@ where fn deserialize_multi_kv( store: &dyn Storage, pk_namespace: &[u8], - kv: KV, -) -> StdResult> { + kv: Pair, +) -> StdResult> { let (key, pk_len) = kv; // Deserialize pk_len @@ -175,7 +175,7 @@ where &self, store: &'c dyn Storage, prefix: K::Prefix, - ) -> StdResult>> { + ) -> StdResult>> { self.prefix(prefix) .range(store, None, None, Order::Ascending) .collect() @@ -197,7 +197,7 @@ where min: Option, max: Option, order: Order, - ) -> Box>> + 'c> + ) -> Box>> + 'c> where T: 'c, { @@ -259,7 +259,7 @@ where } } -fn deserialize_unique_kv(kv: KV) -> StdResult> { +fn deserialize_unique_kv(kv: Pair) -> StdResult> { let (_, v) = kv; let t = from_slice::>(&v)?; Ok((t.pk.into(), t.value)) @@ -283,7 +283,7 @@ where } /// returns all items that match this secondary index, always by pk Ascending - pub fn item(&self, store: &dyn Storage, idx: K) -> StdResult>> { + pub fn item(&self, store: &dyn Storage, idx: K) -> StdResult>> { let data = self .idx_map .may_load(store, idx)? @@ -307,7 +307,7 @@ where min: Option, max: Option, order: Order, - ) -> Box>> + 'c> + ) -> Box>> + 'c> where T: 'c, { diff --git a/packages/storage-plus/src/iter_helpers.rs b/packages/storage-plus/src/iter_helpers.rs index 4811a7244..1d6800f4a 100644 --- a/packages/storage-plus/src/iter_helpers.rs +++ b/packages/storage-plus/src/iter_helpers.rs @@ -2,12 +2,12 @@ use serde::de::DeserializeOwned; -use cosmwasm_std::KV; +use cosmwasm_std::Pair; use cosmwasm_std::{from_slice, StdResult}; use crate::helpers::encode_length; -pub(crate) fn deserialize_kv(kv: KV) -> StdResult> { +pub(crate) fn deserialize_kv(kv: Pair) -> StdResult> { let (k, v) = kv; let t = from_slice::(&v)?; Ok((k, t)) @@ -146,7 +146,7 @@ mod namespace_test { // ensure we get proper result from prefixed_range iterator let iter = range_with_prefix(&storage, &prefix, None, None, Order::Descending); - let elements: Vec = iter.collect(); + let elements: Vec = iter.collect(); assert_eq!( elements, vec![ @@ -171,14 +171,14 @@ mod namespace_test { set_with_prefix(&mut storage, &other_prefix, b"moon", b"buggy"); // make sure start and end are applied properly - let res: Vec = + let res: Vec = range_with_prefix(&storage, &prefix, Some(b"b"), Some(b"c"), Order::Ascending) .collect(); assert_eq!(res.len(), 1); assert_eq!(res[0], (b"bar".to_vec(), b"none".to_vec())); // make sure start and end are applied properly - let res: Vec = range_with_prefix( + let res: Vec = range_with_prefix( &storage, &prefix, Some(b"bas"), @@ -188,7 +188,7 @@ mod namespace_test { .collect(); assert_eq!(res.len(), 0); - let res: Vec = + let res: Vec = range_with_prefix(&storage, &prefix, Some(b"ant"), None, Order::Ascending).collect(); assert_eq!(res.len(), 2); assert_eq!(res[0], (b"bar".to_vec(), b"none".to_vec())); diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index c025f12dd..43e85c1fd 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -93,7 +93,7 @@ where min: Option, max: Option, order: cosmwasm_std::Order, - ) -> Box>> + 'c> + ) -> Box>> + 'c> where T: 'c, { diff --git a/packages/storage-plus/src/prefix.rs b/packages/storage-plus/src/prefix.rs index 08d125c4d..3bc16517c 100644 --- a/packages/storage-plus/src/prefix.rs +++ b/packages/storage-plus/src/prefix.rs @@ -3,7 +3,7 @@ use serde::de::DeserializeOwned; use serde::Serialize; use std::marker::PhantomData; -use cosmwasm_std::{Order, StdResult, Storage, KV}; +use cosmwasm_std::{Order, Pair, StdResult, Storage}; use std::ops::Deref; use crate::helpers::nested_namespaces_with_key; @@ -42,7 +42,7 @@ impl Bound { } } -type DeserializeFn = fn(&dyn Storage, &[u8], KV) -> StdResult>; +type DeserializeFn = fn(&dyn Storage, &[u8], Pair) -> StdResult>; #[derive(Clone)] pub struct Prefix @@ -100,7 +100,7 @@ where min: Option, max: Option, order: Order, - ) -> Box>> + 'a> + ) -> Box>> + 'a> where T: 'a, { @@ -133,7 +133,7 @@ pub fn range_with_prefix<'a>( start: Option, end: Option, order: Order, -) -> Box + 'a> { +) -> Box + 'a> { let start = calc_start_bound(namespace, start); let end = calc_end_bound(namespace, end); diff --git a/packages/storage-plus/src/snapshot.rs b/packages/storage-plus/src/snapshot.rs index 95d1070df..d8d0b4f37 100644 --- a/packages/storage-plus/src/snapshot.rs +++ b/packages/storage-plus/src/snapshot.rs @@ -253,7 +253,7 @@ where min: Option, max: Option, order: cosmwasm_std::Order, - ) -> Box>> + 'c> + ) -> Box>> + 'c> where T: 'c, {