cargo fmt

This commit is contained in:
Giles Cope
2021-09-19 10:49:24 +01:00
parent 364ed8bed1
commit 8fe5ebbc00
3 changed files with 108 additions and 47 deletions
+8 -2
View File
@@ -16,10 +16,16 @@
use jsonrpsee_types::Error as RequestError; use jsonrpsee_types::Error as RequestError;
use sp_core::crypto::SecretStringError; use sp_core::crypto::SecretStringError;
use sp_runtime::{transaction_validity::TransactionValidityError, DispatchError}; use sp_runtime::{
transaction_validity::TransactionValidityError,
DispatchError,
};
use thiserror::Error; use thiserror::Error;
use crate::metadata::{Metadata, MetadataError}; use crate::metadata::{
Metadata,
MetadataError,
};
/// Error enum. /// Error enum.
#[derive(Debug, Error)] #[derive(Debug, Error)]
+54 -21
View File
@@ -14,22 +14,46 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>. // along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use codec::{Codec, Compact, Decode, Encode, Input, Output}; use codec::{
Codec,
Compact,
Decode,
Encode,
Input,
Output,
};
use dyn_clone::DynClone; use dyn_clone::DynClone;
use sp_runtime::{DispatchError, DispatchResult}; use sp_runtime::{
DispatchError,
DispatchResult,
};
use std::{ use std::{
collections::{ collections::{
hash_map::{Entry, HashMap}, hash_map::{
Entry,
HashMap,
},
HashSet, HashSet,
}, },
fmt, fmt,
marker::{PhantomData, Send}, marker::{
PhantomData,
Send,
},
}; };
use crate::{ use crate::{
error::{Error, RuntimeError}, error::{
metadata::{EventArg, Metadata}, Error,
Phase, Runtime, System, RuntimeError,
},
metadata::{
EventArg,
Metadata,
},
Phase,
Runtime,
System,
}; };
/// Raw bytes for an Event /// Raw bytes for an Event
@@ -182,18 +206,20 @@ impl<T: Runtime + System> EventsDecoder<T> {
self.decode_raw_bytes(&[*arg.clone()], input, output, errors)? self.decode_raw_bytes(&[*arg.clone()], input, output, errors)?
} }
} }
EventArg::Option(arg) => match input.read_byte()? { EventArg::Option(arg) => {
0 => output.push_byte(0), match input.read_byte()? {
1 => { 0 => output.push_byte(0),
output.push_byte(1); 1 => {
self.decode_raw_bytes(&[*arg.clone()], input, output, errors)? output.push_byte(1);
self.decode_raw_bytes(&[*arg.clone()], input, output, errors)?
}
_ => {
return Err(Error::Other(
"unexpected first byte decoding Option".into(),
))
}
} }
_ => { }
return Err(Error::Other(
"unexpected first byte decoding Option".into(),
))
}
},
EventArg::Tuple(args) => { EventArg::Tuple(args) => {
self.decode_raw_bytes(args, input, output, errors)? self.decode_raw_bytes(args, input, output, errors)?
} }
@@ -208,7 +234,7 @@ impl<T: Runtime + System> EventsDecoder<T> {
output.write(&buf); output.write(&buf);
Ok(()) Ok(())
} else { } else {
return Err(Error::TypeSizeUnavailable(name.to_owned())); return Err(Error::TypeSizeUnavailable(name.to_owned()))
} }
} }
}; };
@@ -328,8 +354,15 @@ pub enum Raw {
mod tests { mod tests {
use super::*; use super::*;
use frame_metadata::{ use frame_metadata::{
DecodeDifferent, ErrorMetadata, EventMetadata, ExtrinsicMetadata, ModuleMetadata, DecodeDifferent,
RuntimeMetadata, RuntimeMetadataPrefixed, RuntimeMetadataV13, META_RESERVED, ErrorMetadata,
EventMetadata,
ExtrinsicMetadata,
ModuleMetadata,
RuntimeMetadata,
RuntimeMetadataPrefixed,
RuntimeMetadataV13,
META_RESERVED,
}; };
use std::convert::TryFrom; use std::convert::TryFrom;
+46 -24
View File
@@ -14,13 +14,27 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>. // along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use std::{collections::HashMap, convert::TryFrom, marker::PhantomData, str::FromStr}; use std::{
collections::HashMap,
convert::TryFrom,
marker::PhantomData,
str::FromStr,
};
use codec::{Decode, Encode, Error as CodecError}; use codec::{
Decode,
Encode,
Error as CodecError,
};
use frame_metadata::{ use frame_metadata::{
DecodeDifferent, RuntimeMetadata, RuntimeMetadataPrefixed, StorageEntryModifier, DecodeDifferent,
StorageEntryType, StorageHasher, META_RESERVED, RuntimeMetadata,
RuntimeMetadataPrefixed,
StorageEntryModifier,
StorageEntryType,
StorageHasher,
META_RESERVED,
}; };
use sp_core::storage::StorageKey; use sp_core::storage::StorageKey;
@@ -278,11 +292,13 @@ impl StorageMetadata {
StorageHasher::Blake2_256 => sp_core::blake2_256(bytes).to_vec(), StorageHasher::Blake2_256 => sp_core::blake2_256(bytes).to_vec(),
StorageHasher::Twox128 => sp_core::twox_128(bytes).to_vec(), StorageHasher::Twox128 => sp_core::twox_128(bytes).to_vec(),
StorageHasher::Twox256 => sp_core::twox_256(bytes).to_vec(), StorageHasher::Twox256 => sp_core::twox_256(bytes).to_vec(),
StorageHasher::Twox64Concat => sp_core::twox_64(bytes) StorageHasher::Twox64Concat => {
.iter() sp_core::twox_64(bytes)
.chain(bytes) .iter()
.cloned() .chain(bytes)
.collect(), .cloned()
.collect()
}
} }
} }
@@ -292,20 +308,24 @@ impl StorageMetadata {
pub fn plain(&self) -> Result<StoragePlain, MetadataError> { pub fn plain(&self) -> Result<StoragePlain, MetadataError> {
match &self.ty { match &self.ty {
StorageEntryType::Plain(_) => Ok(StoragePlain { StorageEntryType::Plain(_) => {
prefix: self.prefix().0, Ok(StoragePlain {
}), prefix: self.prefix().0,
})
}
_ => Err(MetadataError::StorageTypeError), _ => Err(MetadataError::StorageTypeError),
} }
} }
pub fn map<K: Encode>(&self) -> Result<StorageMap<K>, MetadataError> { pub fn map<K: Encode>(&self) -> Result<StorageMap<K>, MetadataError> {
match &self.ty { match &self.ty {
StorageEntryType::Map { hasher, .. } => Ok(StorageMap { StorageEntryType::Map { hasher, .. } => {
_marker: PhantomData, Ok(StorageMap {
prefix: self.prefix().0, _marker: PhantomData,
hasher: hasher.clone(), prefix: self.prefix().0,
}), hasher: hasher.clone(),
})
}
_ => Err(MetadataError::StorageTypeError), _ => Err(MetadataError::StorageTypeError),
} }
} }
@@ -318,12 +338,14 @@ impl StorageMetadata {
hasher, hasher,
key2_hasher, key2_hasher,
.. ..
} => Ok(StorageDoubleMap { } => {
_marker: PhantomData, Ok(StorageDoubleMap {
prefix: self.prefix().0, _marker: PhantomData,
hasher1: hasher.clone(), prefix: self.prefix().0,
hasher2: key2_hasher.clone(), hasher1: hasher.clone(),
}), hasher2: key2_hasher.clone(),
})
}
_ => Err(MetadataError::StorageTypeError), _ => Err(MetadataError::StorageTypeError),
} }
} }
@@ -504,7 +526,7 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
fn try_from(metadata: RuntimeMetadataPrefixed) -> Result<Self, Self::Error> { fn try_from(metadata: RuntimeMetadataPrefixed) -> Result<Self, Self::Error> {
if metadata.0 != META_RESERVED { if metadata.0 != META_RESERVED {
return Err(ConversionError::InvalidPrefix.into()); return Err(ConversionError::InvalidPrefix.into())
} }
let meta = match metadata.1 { let meta = match metadata.1 {
RuntimeMetadata::V13(meta) => meta, RuntimeMetadata::V13(meta) => meta,