Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use codec::{
Codec,
Decode,
};
use frame_metadata::StorageEntryModifier;
use futures::future;
use jsonrpsee_http_client::{
HttpClient,
Expand Down Expand Up @@ -360,8 +361,12 @@ impl<T: Runtime> Client<T> {
&self,
key: StorageKey,
hash: Option<T::Hash>,
modifier: StorageEntryModifier,
) -> Result<Option<V>, Error> {
if let Some(data) = self.rpc.storage(&key, hash).await? {
if let Some(mut data) = self.rpc.storage(&key, hash).await? {
if modifier == StorageEntryModifier::Optional {
data.0.insert(0, 1u8)
}
Ok(Some(Decode::decode(&mut &data.0[..])?))
} else {
Ok(None)
Expand All @@ -375,7 +380,9 @@ impl<T: Runtime> Client<T> {
hash: Option<T::Hash>,
) -> Result<Option<F::Returns>, Error> {
let key = store.key(&self.metadata)?;
self.fetch_unhashed::<F::Returns>(key, hash).await
let storage_meta = self.metadata.module(F::MODULE)?.storage(F::FIELD)?;
self.fetch_unhashed::<F::Returns>(key, hash, storage_meta.modifier())
.await
}

/// Fetch a StorageKey that has a default value with an optional block hash.
Expand Down
4 changes: 4 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ impl StorageMetadata {
StorageKey(bytes)
}

pub fn modifier(&self) -> StorageEntryModifier {
self.modifier.clone()
}

pub fn default<V: Decode>(&self) -> Result<V, MetadataError> {
Decode::decode(&mut &self.default[..]).map_err(MetadataError::DefaultError)
}
Expand Down