Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Plaza committed Sep 20, 2020
1 parent 11c594a commit f60833b
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 92 deletions.
4 changes: 2 additions & 2 deletions core/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl Decoder {
let ty = match ty {
RustTypeMarker::TypePointer(v) => {
log::debug!("Resolving: {}", v);

if let Some(t) = self.decode_sub_type(spec, v, data, cursor, is_compact)? {
t
} else {
Expand Down Expand Up @@ -731,7 +731,7 @@ impl Decoder {
match &data {
pallet_identity::Data::None => (),
pallet_identity::Data::Raw(v) => *cursor += v.len(),
_ => *cursor += 32
_ => *cursor += 32,
}
Ok(Some(SubstrateType::Data(data)))
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/decoder/extrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Generic Extrinsic Type and Functions
use crate::substrate_types::SubstrateType;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Serialize, Deserialize)]
pub struct ExtrinsicArgument {
Expand Down
9 changes: 4 additions & 5 deletions core/src/decoder/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use codec::{Decode, Encode, EncodeAsRef, HasCompact};
use primitives::{storage::StorageKey, twox_128};
use runtime_metadata_latest::{StorageEntryModifier, StorageHasher};
use std::error::Error as _;
use thiserror::Error;
use std::{
collections::{HashMap, HashSet},
convert::TryInto,
Expand All @@ -50,6 +49,7 @@ use std::{
str::FromStr,
sync::Arc,
};
use thiserror::Error;

/// Newtype struct around a Vec<u8> (vector of bytes)
#[derive(Clone)]
Expand Down Expand Up @@ -109,15 +109,15 @@ impl From<Vec<u8>> for Metadata {

impl From<&[u8]> for Metadata {
fn from(bytes: &[u8]) -> Metadata {
Metadata::new(bytes)
Metadata::new(bytes)
}
}

impl From<&Metadata> for Metadata {
fn from(meta: &Metadata) -> Metadata {
meta.clone()
}
}
}

impl Metadata {
/// Create a new Metadata type from raw encoded bytes
Expand Down Expand Up @@ -150,8 +150,7 @@ impl Metadata {
}
0x09 => {
let meta: runtime_metadata09::RuntimeMetadataPrefixed =
Decode::decode(&mut &bytes[..])
.expect("Decode Failed");
Decode::decode(&mut &bytes[..]).expect("Decode Failed");
meta.try_into().expect("Conversion Failed")
}
0xA => {
Expand Down
4 changes: 3 additions & 1 deletion core/src/decoder/metadata/version_09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ impl From<TempStorageHasher> for runtime_metadata_latest::StorageHasher {
match hasher {
StorageHasher::Blake2_128 => runtime_metadata_latest::StorageHasher::Blake2_128,
StorageHasher::Blake2_256 => runtime_metadata_latest::StorageHasher::Blake2_256,
StorageHasher::Blake2_128Concat => runtime_metadata_latest::StorageHasher::Blake2_128Concat,
StorageHasher::Blake2_128Concat => {
runtime_metadata_latest::StorageHasher::Blake2_128Concat
}
StorageHasher::Twox128 => runtime_metadata_latest::StorageHasher::Twox128,
StorageHasher::Twox256 => runtime_metadata_latest::StorageHasher::Twox256,
StorageHasher::Twox64Concat => runtime_metadata_latest::StorageHasher::Twox64Concat,
Expand Down
2 changes: 1 addition & 1 deletion core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum Error {
#[error("error: {0}")]
Fail(String),
#[error("parse error {0}")]
Regex(#[from] onig::Error)
Regex(#[from] onig::Error),
}

impl From<&str> for Error {
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,3 @@ impl Display for RustTypeMarker {
write!(f, "{}", type_marker)
}
}

12 changes: 5 additions & 7 deletions core/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ enum RegexSet {
Generic,
}


impl RegexSet {
/// Checks if string matches any of the patterns defined
/// Returns none if it does not match
Expand Down Expand Up @@ -105,8 +104,7 @@ pub fn rust_compact_decl() -> Regex {

/// Match a rust Boxed type
pub fn rust_box_decl() -> Regex {
Regex::new(r"^Box<(?<type>[\w><,(): ]+)>")
.expect("Regex expression should be infallible; qed")
Regex::new(r"^Box<(?<type>[\w><,(): ]+)>").expect("Regex expression should be infallible; qed")
}

/// Match a Rust Generic Type Declaration
Expand Down Expand Up @@ -143,7 +141,7 @@ pub fn rust_tuple_decl() -> Regex {
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*,? *([\w><:()\n]+)*"#,
r#",? *([\w><:()\n]+)*\)$"#,
Expand Down Expand Up @@ -296,15 +294,15 @@ fn parse_regex_compact(s: &str) -> Option<RustTypeMarker> {

/// Parse a Box
/// Boxes are a purely rust memory-management phenomenon.
/// We only care about the underlying data structure.
/// We only care about the underlying data structure.
/// So we do not preserve the fact that this type is 'boxed'.
fn parse_regex_box(s: &str) -> Option<RustTypeMarker> {
let re = rust_box_decl();
if !re.is_match(s) {
return None;
}
let ty = re.captures(s)?.at(1)?;

Some(parse(ty).expect("Should always be some type; qed"))
}

Expand Down Expand Up @@ -850,7 +848,7 @@ mod tests {
fn should_not_overflow_retry_limit() {
let re = rust_tuple_decl();
let tuple = "(ParaId, Option<(CollatorId, Retriable)>)";
assert!(re.is_match(tuple))
assert!(re.is_match(tuple))
}

#[test]
Expand Down
23 changes: 12 additions & 11 deletions core/src/substrate_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
mod remote;

use self::remote::*;
use crate::SetField;
use primitives::crypto::AccountId32;
use primitives::crypto::{Ss58AddressFormat, Ss58Codec};
use serde::{Deserialize, Serialize};
use std::fmt;
use primitives::crypto::AccountId32;
use self::remote::*;

pub type Address = pallet_indices::address::Address<AccountId32, u32>;
pub type Vote = pallet_democracy::Vote;
Expand All @@ -48,17 +48,17 @@ pub enum SubstrateType {
Call(Vec<(String, SubstrateType)>),
/// Era
Era(runtime_primitives::generic::Era),

/// Vote
#[serde(with = "RemoteVote")]
GenericVote(pallet_democracy::Vote),

/// Substrate Indices Address Type
// TODO: this is not generic for any chain that doesn't use a
// u32 and [u8; 32] for its index/id
#[serde(with = "RemoteAddress")]
Address(Address),

#[serde(with = "RemoteData")]
Data(Data),

Expand Down Expand Up @@ -132,9 +132,12 @@ impl fmt::Display for SubstrateType {
runtime_primitives::generic::Era::Mortal(s, e) => write!(f, "Era {}..{}", s, e),
runtime_primitives::generic::Era::Immortal => write!(f, "Immortal Era"),
},
SubstrateType::GenericVote(v) => {
write!(f, "Aye={}, Conviction={}", v.aye, v.conviction.lock_periods())
},
SubstrateType::GenericVote(v) => write!(
f,
"Aye={}, Conviction={}",
v.aye,
v.conviction.lock_periods()
),
SubstrateType::Address(v) => {
match v {
pallet_indices::address::Address::Id(ref i) => {
Expand All @@ -147,10 +150,8 @@ impl fmt::Display for SubstrateType {
}
pallet_indices::address::Address::Index(i) => write!(f, "Index: {:?}", i),
}
},
SubstrateType::Data(d) => {
write!(f, "{:?}", d)
}
SubstrateType::Data(d) => write!(f, "{:?}", d),
SubstrateType::SignedExtra(v) => write!(f, "{}", v),
SubstrateType::Composite(v) => {
let mut s = String::from("");
Expand Down
69 changes: 34 additions & 35 deletions core/src/substrate_types/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with substrate-desub. If not, see <http://www.gnu.org/licenses/>.

use serde::{Deserialize, Serialize};
use primitives::crypto::AccountId32;
use serde::{Deserialize, Serialize};

use super::{Address, Vote, Conviction, Data};
use super::{Address, Conviction, Data, Vote};

#[derive(Serialize, Deserialize)]
#[serde(remote = "Address")]
Expand All @@ -29,9 +29,9 @@ pub enum RemoteAddress {
#[derive(Serialize, Deserialize)]
#[serde(remote = "Vote")]
pub struct RemoteVote {
pub aye: bool,
pub aye: bool,
#[serde(with = "RemoteConviction")]
pub conviction: Conviction,
pub conviction: Conviction,
}

/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
Expand All @@ -41,40 +41,39 @@ pub struct RemoteVote {
#[derive(Serialize, Deserialize)]
#[serde(remote = "Data")]
pub enum RemoteData {
/// No data here.
None,
/// The data is stored directly.
Raw(Vec<u8>),
/// Only the Blake2 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
BlakeTwo256([u8; 32]),
/// Only the SHA2-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
Sha256([u8; 32]),
/// Only the Keccak-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
Keccak256([u8; 32]),
/// Only the SHA3-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
ShaThree256([u8; 32]),
/// No data here.
None,
/// The data is stored directly.
Raw(Vec<u8>),
/// Only the Blake2 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
BlakeTwo256([u8; 32]),
/// Only the SHA2-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
Sha256([u8; 32]),
/// Only the Keccak-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
Keccak256([u8; 32]),
/// Only the SHA3-256 hash of the data is stored. The preimage of the hash may be retrieved
/// through some hash-lookup service.
ShaThree256([u8; 32]),
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "Conviction")]
pub enum RemoteConviction {
/// 0.1x votes, unlocked.
None,
/// 1x votes, locked for an enactment period following a successful vote.
Locked1x,
/// 2x votes, locked for 2x enactment periods following a successful vote.
Locked2x,
/// 3x votes, locked for 4x...
Locked3x,
/// 4x votes, locked for 8x...
Locked4x,
/// 5x votes, locked for 16x...
Locked5x,
/// 6x votes, locked for 32x...
Locked6x,
/// 0.1x votes, unlocked.
None,
/// 1x votes, locked for an enactment period following a successful vote.
Locked1x,
/// 2x votes, locked for 2x enactment periods following a successful vote.
Locked2x,
/// 3x votes, locked for 4x...
Locked3x,
/// 4x votes, locked for 8x...
Locked4x,
/// 5x votes, locked for 16x...
Locked5x,
/// 6x votes, locked for 32x...
Locked6x,
}

1 change: 1 addition & 0 deletions extras/src/definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion extras/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ pub enum Error {
#[error("{0} Not Found")]
NotFound(String),
}

12 changes: 5 additions & 7 deletions extras/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#[cfg(feature = "default")]
mod definitions;

mod overrides;
mod error;
mod extrinsics;
mod modules;
mod overrides;
mod resolver;
mod error;

pub use self::overrides::*;
pub use self::error::*;
pub use self::extrinsics::*;
pub use self::modules::*;
pub use self::error::*;
pub use self::overrides::*;
pub use self::resolver::{Builder as TypeResolverBuilder, TypeResolver};


use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
/// An overrides for a range of runtime versions
#[derive(Debug, Serialize, Deserialize, Default, Eq, PartialEq, Clone)]
pub struct TypeRange {
Expand All @@ -37,4 +36,3 @@ fn is_in_range(spec: u32, over_ride: &TypeRange) -> bool {
[None, None] => true,
}
}

Loading

0 comments on commit f60833b

Please sign in to comment.