Remove unwrap and format code (#62)

* Remove unwrap from metadata fetch

* Format code
This commit is contained in:
Andrew Jones
2020-01-09 17:26:50 +00:00
committed by GitHub
parent b159d0dae1
commit f998444619
4 changed files with 37 additions and 12 deletions
+6 -1
View File
@@ -140,7 +140,12 @@ impl<T: System + Balances + 'static> EventsDecoder<T> {
&& !self.type_sizes.contains_key(&primitive)
&& !primitive.contains("PhantomData")
{
missing.insert(format!("{}::{}::{}", module.name(), event.name, primitive));
missing.insert(format!(
"{}::{}::{}",
module.name(),
event.name,
primitive
));
}
}
}
+10 -2
View File
@@ -72,7 +72,10 @@ pub use self::{
runtimes::*,
};
use self::{
events::{EventsDecoder, EventsError},
events::{
EventsDecoder,
EventsError,
},
extrinsic::{
DefaultExtra,
SignedExtra,
@@ -400,7 +403,12 @@ where
T::Address: From<T::AccountId>,
{
/// Access the events decoder for registering custom type sizes
pub fn events_decoder<F: FnOnce(&mut EventsDecoder<T>) -> Result<usize, EventsError>>(self, f: F) -> Self {
pub fn events_decoder<
F: FnOnce(&mut EventsDecoder<T>) -> Result<usize, EventsError>,
>(
self,
f: F,
) -> Self {
let mut this = self;
if let Ok(ref mut decoder) = this.decoder {
if let Err(err) = f(decoder) {
+7 -3
View File
@@ -145,10 +145,14 @@ impl<T: System> Rpc<T> {
pub fn metadata(&self) -> impl Future<Item = Metadata, Error = Error> {
self.state
.metadata(None)
.map(|bytes| Decode::decode(&mut &bytes[..]).unwrap())
.map_err(Into::into)
.and_then(|meta: RuntimeMetadataPrefixed| {
future::result(meta.try_into().map_err(|err| format!("{:?}", err).into()))
.and_then(|bytes| {
let result = Decode::decode(&mut &bytes[..])
.map_err(Into::into)
.and_then(|meta: RuntimeMetadataPrefixed| {
meta.try_into().map_err(|err| format!("{:?}", err).into())
});
future::result(result)
})
}