diff --git a/trie-db/src/fatdb.rs b/trie-db/src/fatdb.rs index e5d4a198..bcb317c8 100644 --- a/trie-db/src/fatdb.rs +++ b/trie-db/src/fatdb.rs @@ -53,11 +53,11 @@ where { fn root(&self) -> &TrieHash { self.raw.root() } - fn contains(&self, key: &[u8]) -> Result, CError> { + fn contains(&mut self, key: &[u8]) -> Result, CError> { self.raw.contains(L::Hash::hash(key).as_ref()) } - fn get_with<'a, 'key, Q: Query>(&'a self, key: &'key [u8], query: Q) + fn get_with<'a, 'key, Q: Query>(&'a mut self, key: &'key [u8], query: Q) -> Result, TrieHash, CError> where 'a: 'key { diff --git a/trie-db/src/lib.rs b/trie-db/src/lib.rs index 37bfe64e..a3c72aac 100644 --- a/trie-db/src/lib.rs +++ b/trie-db/src/lib.rs @@ -178,13 +178,13 @@ pub trait Trie { fn is_empty(&self) -> bool { *self.root() == L::Codec::hashed_null_node() } /// Does the trie contain a given key? - fn contains(&self, key: &[u8]) -> Result, CError> { - self.get(key).map(|x| x.is_some() ) + fn contains(&mut self, key: &[u8]) -> Result, CError> { + self.get(key).map(|x| x.is_some()) } /// What is the value of the given key in this trie? fn get<'a, 'key>( - &'a self, + &'a mut self, key: &'key [u8], ) -> Result, TrieHash, CError> where 'a: 'key { self.get_with(key, |v: &[u8]| v.to_vec() ) @@ -193,7 +193,7 @@ pub trait Trie { /// Search for the key with the given query parameter. See the docs of the `Query` /// trait for more details. fn get_with<'a, 'key, Q: Query>( - &'a self, + &'a mut self, key: &'key [u8], query: Q ) -> Result, TrieHash, CError> where 'a: 'key; @@ -300,17 +300,26 @@ impl<'db, L: TrieLayout> Trie for TrieKinds<'db, L> { wrapper!(self, is_empty,) } - fn contains(&self, key: &[u8]) -> Result, CError> { - wrapper!(self, contains, key) + fn contains(&mut self, key: &[u8]) -> Result, CError> { + match self { + TrieKinds::Generic(ref mut t) => t.contains(key), + TrieKinds::Secure(ref mut t) => t.contains(key), + TrieKinds::Fat(ref mut t) => t.contains(key), + } } fn get_with<'a, 'key, Q: Query>( - &'a self, key: &'key [u8], + &'a mut self, + key: &'key [u8], query: Q, ) -> Result, TrieHash, CError> where 'a: 'key { - wrapper!(self, get_with, key, query) + match self { + TrieKinds::Generic(ref mut t) => t.get_with(key, query), + TrieKinds::Secure(ref mut t) => t.get_with(key, query), + TrieKinds::Fat(ref mut t) => t.get_with(key, query), + } } fn iter<'a>(&'a self) -> Result< diff --git a/trie-db/src/proof/generate.rs b/trie-db/src/proof/generate.rs index 817e9333..08789dbe 100644 --- a/trie-db/src/proof/generate.rs +++ b/trie-db/src/proof/generate.rs @@ -218,7 +218,7 @@ impl<'a, C: NodeCodec> StackEntry<'a, C> { /// Generate a compact proof for key-value pairs in a trie given a set of keys. /// /// Assumes inline nodes have only inline children. -pub fn generate_proof<'a, T, L, I, K>(trie: &T, keys: I) +pub fn generate_proof<'a, T, L, I, K>(trie: &mut T, keys: I) -> TrieResult>, TrieHash, CError> where T: Trie, diff --git a/trie-db/src/sectriedb.rs b/trie-db/src/sectriedb.rs index 8b047135..33362d14 100644 --- a/trie-db/src/sectriedb.rs +++ b/trie-db/src/sectriedb.rs @@ -60,12 +60,12 @@ where { fn root(&self) -> &TrieHash { self.raw.root() } - fn contains(&self, key: &[u8]) -> Result, CError> { + fn contains(&mut self, key: &[u8]) -> Result, CError> { self.raw.contains(L::Hash::hash(key).as_ref()) } fn get_with<'a, 'key, Q: Query>( - &'a self, + &'a mut self, key: &'key [u8], query: Q, ) -> Result, TrieHash, CError> diff --git a/trie-db/src/triedb.rs b/trie-db/src/triedb.rs index 385f08f9..eb91ec08 100644 --- a/trie-db/src/triedb.rs +++ b/trie-db/src/triedb.rs @@ -153,7 +153,7 @@ where fn root(&self) -> &TrieHash { self.root } fn get_with<'a, 'key, Q: Query>( - &'a self, + &'a mut self, key: &'key [u8], query: Q, ) -> Result, TrieHash, CError>