From 59b9c117b76f68ec480729f03ef644954b8b555c Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Fri, 14 Aug 2020 04:06:30 +0800 Subject: [PATCH] Add a method to fetch an unhashed key, close #100 (#152) * Add a method to fetch an unhashed key, close #100 * Return decoded value * Refactoring --- src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b98755625f..e1a75a4011 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,19 @@ impl Client { &self.metadata } + /// Fetch the value under an unhashed storage key + pub async fn fetch_unhashed( + &self, + key: StorageKey, + hash: Option, + ) -> 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. pub async fn fetch>( &self, @@ -265,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.