mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
* Add a method to fetch an unhashed key, close #100 * Return decoded value * Refactoring
This commit is contained in:
+14
-5
@@ -258,6 +258,19 @@ impl<T: Runtime> Client<T> {
|
||||
&self.metadata
|
||||
}
|
||||
|
||||
/// Fetch the value under an unhashed storage key
|
||||
pub async fn fetch_unhashed<V: Decode>(
|
||||
&self,
|
||||
key: StorageKey,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<V>, 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<F: Store<T>>(
|
||||
&self,
|
||||
@@ -265,11 +278,7 @@ impl<T: Runtime> Client<T> {
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<F::Returns>, 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::<F::Returns>(key, hash).await
|
||||
}
|
||||
|
||||
/// Fetch a StorageKey that has a default value with an optional block hash.
|
||||
|
||||
Reference in New Issue
Block a user