Skip to content

Commit

Permalink
Add a method to fetch an unhashed key, close paritytech#100 (parityte…
Browse files Browse the repository at this point in the history
…ch#152)

* Add a method to fetch an unhashed key, close paritytech#100

* Return decoded value

* Refactoring
  • Loading branch information
en committed Aug 13, 2020
1 parent 9aa32ef commit 59b9c11
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,29 @@ impl<T: Runtime> Client<T> {
&self.metadata
}

/// Fetch a StorageKey with an optional block hash.
pub async fn fetch<F: Store<T>>(
/// Fetch the value under an unhashed storage key
pub async fn fetch_unhashed<V: Decode>(
&self,
store: &F,
key: StorageKey,
hash: Option<T::Hash>,
) -> Result<Option<F::Returns>, Error> {
let key = store.key(&self.metadata)?;
) -> 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,
store: &F,
hash: Option<T::Hash>,
) -> Result<Option<F::Returns>, Error> {
let key = store.key(&self.metadata)?;
self.fetch_unhashed::<F::Returns>(key, hash).await
}

/// Fetch a StorageKey that has a default value with an optional block hash.
pub async fn fetch_or_default<F: Store<T>>(
&self,
Expand Down

0 comments on commit 59b9c11

Please sign in to comment.