From cf3d5d3031431f94e09a05502b0683adf1583fab Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Thu, 13 Aug 2020 19:24:54 +0800 Subject: [PATCH 1/3] Add a method to fetch an unhashed key, close #100 --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b790083cd8a..949b0b857ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,15 @@ impl Client { &self.metadata } + /// Fetch the value under an unhashed storage key + pub async fn fetch_unhashed( + &self, + key: &StorageKey, + hash: Option, + ) -> Result, Error> { + self.rpc.storage(key, hash).await + } + /// Fetch a StorageKey with an optional block hash. pub async fn fetch>( &self, From cc3e5d16e87fca0ef2446a0bd1b6dd0025b32411 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Fri, 14 Aug 2020 00:29:00 +0800 Subject: [PATCH 2/3] Return decoded value --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 949b0b857ce..1efe1d34a1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,12 +259,16 @@ impl Client { } /// Fetch the value under an unhashed storage key - pub async fn fetch_unhashed( + pub async fn fetch_unhashed( &self, - key: &StorageKey, + key: StorageKey, hash: Option, - ) -> Result, Error> { - self.rpc.storage(key, hash).await + ) -> Result, Error> { + if let Some(data) = self.rpc.storage(&key, hash).await? { + Ok(Some(Decode::decode(&mut &data.0[..])?)) + } else { + Ok(None) + } } /// Fetch a StorageKey with an optional block hash. From 5d5b28bd84f76161977907006ed68efd9460a008 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Fri, 14 Aug 2020 00:49:23 +0800 Subject: [PATCH 3/3] Refactoring --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1efe1d34a1d..e6ac9e1ef3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -278,11 +278,7 @@ impl Client { hash: Option, ) -> Result, Error> { let key = store.key(&self.metadata)?; - if let Some(data) = self.rpc.storage(&key, hash).await? { - Ok(Some(Decode::decode(&mut &data.0[..])?)) - } else { - Ok(None) - } + self.fetch_unhashed::(key, hash).await } /// Fetch a StorageKey that has a default value with an optional block hash.