Don’t panic on storage decode error (#30)

Instead of panicking when the storage data reveived cannot be decoded we
pass on the error.
This commit is contained in:
Thomas Scholtes
2019-11-04 15:21:00 +01:00
committed by Andrew Jones
parent 04c371b32c
commit 5c2eeee1d2
+9 -3
View File
@@ -86,10 +86,16 @@ impl<T: System> Rpc<T> {
) -> impl Future<Item = Option<V>, Error = Error> {
self.state
.storage(key, None)
.map(|data| {
data.map(|d| Decode::decode(&mut &d.0[..]).expect("Valid storage key"))
})
.map_err(Into::into)
.and_then(|data| {
match data {
Some(data) => {
let value = Decode::decode(&mut &data.0[..])?;
Ok(Some(value))
}
None => Ok(None),
}
})
}
/// Fetch the genesis hash