Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -17,7 +17,7 @@
//! Ecdsa crypto types.
use crate::{RuntimePublic, KeyTypeId};
use crate::{KeyTypeId, RuntimePublic};
use sp_std::vec::Vec;
@@ -33,9 +33,9 @@ mod app {
}
}
pub use app::{Public as AppPublic, Signature as AppSignature};
#[cfg(feature = "full_crypto")]
pub use app::Pair as AppPair;
pub use app::{Public as AppPublic, Signature as AppSignature};
impl RuntimePublic for Public {
type Signature = Signature;
@@ -17,7 +17,7 @@
//! Ed25519 crypto types.
use crate::{RuntimePublic, KeyTypeId};
use crate::{KeyTypeId, RuntimePublic};
use sp_std::vec::Vec;
@@ -33,9 +33,9 @@ mod app {
}
}
pub use app::{Public as AppPublic, Signature as AppSignature};
#[cfg(feature = "full_crypto")]
pub use app::Pair as AppPair;
pub use app::{Public as AppPublic, Signature as AppSignature};
impl RuntimePublic for Public {
type Signature = Signature;
@@ -18,15 +18,18 @@
//! Traits and macros for constructing application specific strongly typed crypto wrappers.
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#[doc(hidden)]
pub use sp_core::{self, crypto::{CryptoType, CryptoTypePublicPair, Public, Derive, IsWrappedBy, Wraps}, RuntimeDebug};
pub use sp_core::crypto::{key_types, CryptoTypeId, KeyTypeId};
#[doc(hidden)]
#[cfg(feature = "full_crypto")]
pub use sp_core::crypto::{SecretStringError, DeriveJunction, Ss58Codec, Pair};
pub use sp_core::crypto::{KeyTypeId, CryptoTypeId, key_types};
pub use sp_core::crypto::{DeriveJunction, Pair, SecretStringError, Ss58Codec};
#[doc(hidden)]
pub use sp_core::{
self,
crypto::{CryptoType, CryptoTypePublicPair, Derive, IsWrappedBy, Public, Wraps},
RuntimeDebug,
};
#[doc(hidden)]
pub use codec;
@@ -34,15 +37,11 @@ pub use codec;
#[cfg(feature = "std")]
pub use serde;
#[doc(hidden)]
pub use sp_std::{
convert::TryFrom,
ops::Deref,
vec::Vec,
};
pub use sp_std::{convert::TryFrom, ops::Deref, vec::Vec};
pub mod ecdsa;
pub mod ed25519;
pub mod sr25519;
pub mod ecdsa;
mod traits;
pub use traits::*;
@@ -51,7 +50,7 @@ pub use traits::*;
/// Application-specific types whose identifier is `$key_type`.
///
/// ```rust
///# use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// # use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
/// // of value `b"fuba"`.
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
@@ -61,8 +60,17 @@ pub use traits::*;
macro_rules! app_crypto {
($module:ident, $key_type:expr) => {
$crate::app_crypto_public_full_crypto!($module::Public, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_signature_full_crypto!($module::Signature, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_public_common!(
$module::Public,
$module::Signature,
$key_type,
$module::CRYPTO_ID
);
$crate::app_crypto_signature_full_crypto!(
$module::Signature,
$key_type,
$module::CRYPTO_ID
);
$crate::app_crypto_signature_common!($module::Signature, $key_type);
$crate::app_crypto_pair!($module::Pair, $key_type, $module::CRYPTO_ID);
};
@@ -72,7 +80,7 @@ macro_rules! app_crypto {
/// Application-specific types whose identifier is `$key_type`.
///
/// ```rust
///# use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// # use sp_application_crypto::{app_crypto, wrap, ed25519, KeyTypeId};
/// // Declare a new set of crypto types using Ed25519 logic that identifies as `KeyTypeId`
/// // of value `b"fuba"`.
/// app_crypto!(ed25519, KeyTypeId(*b"_uba"));
@@ -82,8 +90,17 @@ macro_rules! app_crypto {
macro_rules! app_crypto {
($module:ident, $key_type:expr) => {
$crate::app_crypto_public_not_full_crypto!($module::Public, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_public_common!($module::Public, $module::Signature, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_signature_not_full_crypto!($module::Signature, $key_type, $module::CRYPTO_ID);
$crate::app_crypto_public_common!(
$module::Public,
$module::Signature,
$key_type,
$module::CRYPTO_ID
);
$crate::app_crypto_signature_not_full_crypto!(
$module::Signature,
$key_type,
$module::CRYPTO_ID
);
$crate::app_crypto_signature_common!($module::Signature, $key_type);
};
}
@@ -93,7 +110,7 @@ macro_rules! app_crypto {
#[macro_export]
macro_rules! app_crypto_pair {
($pair:ty, $key_type:expr, $crypto_type:expr) => {
$crate::wrap!{
$crate::wrap! {
/// A generic `AppPublic` wrapper type over $pair crypto; this has no specific App.
#[derive(Clone)]
pub struct Pair($pair);
@@ -111,12 +128,16 @@ macro_rules! app_crypto_pair {
$crate::app_crypto_pair_functions_if_std!($pair);
fn derive<
Iter: Iterator<Item=$crate::DeriveJunction>
>(&self, path: Iter, seed: Option<Self::Seed>) -> Result<(Self, Option<Self::Seed>), Self::DeriveError> {
fn derive<Iter: Iterator<Item = $crate::DeriveJunction>>(
&self,
path: Iter,
seed: Option<Self::Seed>,
) -> Result<(Self, Option<Self::Seed>), Self::DeriveError> {
self.0.derive(path, seed).map(|x| (Self(x.0), x.1))
}
fn from_seed(seed: &Self::Seed) -> Self { Self(<$pair>::from_seed(seed)) }
fn from_seed(seed: &Self::Seed) -> Self {
Self(<$pair>::from_seed(seed))
}
fn from_seed_slice(seed: &[u8]) -> Result<Self, $crate::SecretStringError> {
<$pair>::from_seed_slice(seed).map(Self)
}
@@ -137,8 +158,12 @@ macro_rules! app_crypto_pair {
) -> bool {
<$pair>::verify_weak(sig, message, pubkey)
}
fn public(&self) -> Self::Public { Public(self.0.public()) }
fn to_raw_vec(&self) -> $crate::Vec<u8> { self.0.to_raw_vec() }
fn public(&self) -> Self::Public {
Public(self.0.public())
}
fn to_raw_vec(&self) -> $crate::Vec<u8> {
self.0.to_raw_vec()
}
}
impl $crate::AppKey for Pair {
@@ -167,22 +192,22 @@ macro_rules! app_crypto_pair_functions_if_std {
(Self(r.0), r.1, r.2)
}
fn from_phrase(phrase: &str, password: Option<&str>)
-> Result<(Self, Self::Seed), $crate::SecretStringError>
{
fn from_phrase(
phrase: &str,
password: Option<&str>,
) -> Result<(Self, Self::Seed), $crate::SecretStringError> {
<$pair>::from_phrase(phrase, password).map(|r| (Self(r.0), r.1))
}
}
};
}
#[doc(hidden)]
#[cfg(not(feature = "std"))]
#[macro_export]
macro_rules! app_crypto_pair_functions_if_std {
($pair:ty) => {}
($pair:ty) => {};
}
/// Declares Public type which is functionally equivalent to `$public`, but is new
/// Application-specific type whose identifier is `$key_type`.
/// can only be used together with `full_crypto` feature
@@ -191,7 +216,7 @@ macro_rules! app_crypto_pair_functions_if_std {
#[macro_export]
macro_rules! app_crypto_public_full_crypto {
($public:ty, $key_type:expr, $crypto_type:expr) => {
$crate::wrap!{
$crate::wrap! {
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
#[derive(
Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord,
@@ -216,7 +241,7 @@ macro_rules! app_crypto_public_full_crypto {
const ID: $crate::KeyTypeId = $key_type;
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
}
}
};
}
/// Declares Public type which is functionally equivalent to `$public`, but is new
@@ -227,7 +252,7 @@ macro_rules! app_crypto_public_full_crypto {
#[macro_export]
macro_rules! app_crypto_public_not_full_crypto {
($public:ty, $key_type:expr, $crypto_type:expr) => {
$crate::wrap!{
$crate::wrap! {
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
#[derive(
Clone, Default, Eq, PartialEq, Ord, PartialOrd,
@@ -247,7 +272,7 @@ macro_rules! app_crypto_public_not_full_crypto {
const ID: $crate::KeyTypeId = $key_type;
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
}
}
};
}
/// Declares Public type which is functionally equivalent to `$public`, but is new
@@ -260,15 +285,21 @@ macro_rules! app_crypto_public_common {
$crate::app_crypto_public_common_if_std!();
impl AsRef<[u8]> for Public {
fn as_ref(&self) -> &[u8] { self.0.as_ref() }
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl AsMut<[u8]> for Public {
fn as_mut(&mut self) -> &mut [u8] { self.0.as_mut() }
fn as_mut(&mut self) -> &mut [u8] {
self.0.as_mut()
}
}
impl $crate::Public for Public {
fn from_slice(x: &[u8]) -> Self { Self(<$public>::from_slice(x)) }
fn from_slice(x: &[u8]) -> Self {
Self(<$public>::from_slice(x))
}
fn to_public_crypto_pair(&self) -> $crate::CryptoTypePublicPair {
$crate::CryptoTypePublicPair($crypto_type, self.to_raw_vec())
@@ -279,14 +310,20 @@ macro_rules! app_crypto_public_common {
type Generic = $public;
}
impl $crate::RuntimeAppPublic for Public where $public: $crate::RuntimePublic<Signature=$sig> {
impl $crate::RuntimeAppPublic for Public
where
$public: $crate::RuntimePublic<Signature = $sig>,
{
const ID: $crate::KeyTypeId = $key_type;
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
type Signature = Signature;
fn all() -> $crate::Vec<Self> {
<$public as $crate::RuntimePublic>::all($key_type).into_iter().map(Self).collect()
<$public as $crate::RuntimePublic>::all($key_type)
.into_iter()
.map(Self)
.collect()
}
fn generate_pair(seed: Option<$crate::Vec<u8>>) -> Self {
@@ -294,11 +331,8 @@ macro_rules! app_crypto_public_common {
}
fn sign<M: AsRef<[u8]>>(&self, msg: &M) -> Option<Self::Signature> {
<$public as $crate::RuntimePublic>::sign(
self.as_ref(),
$key_type,
msg,
).map(Signature)
<$public as $crate::RuntimePublic>::sign(self.as_ref(), $key_type, msg)
.map(Signature)
}
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
@@ -318,10 +352,7 @@ macro_rules! app_crypto_public_common {
impl From<&Public> for $crate::CryptoTypePublicPair {
fn from(key: &Public) -> Self {
$crate::CryptoTypePublicPair(
$crypto_type,
$crate::Public::to_raw_vec(key),
)
$crate::CryptoTypePublicPair($crypto_type, $crate::Public::to_raw_vec(key))
}
}
@@ -332,7 +363,7 @@ macro_rules! app_crypto_public_common {
<$public>::try_from(data).map(Into::into)
}
}
}
};
}
/// Implements traits for the public key type if `feature = "std"` is enabled.
@@ -342,8 +373,9 @@ macro_rules! app_crypto_public_common {
macro_rules! app_crypto_public_common_if_std {
() => {
impl $crate::Derive for Public {
fn derive<Iter: Iterator<Item=$crate::DeriveJunction>>(&self,
path: Iter
fn derive<Iter: Iterator<Item = $crate::DeriveJunction>>(
&self,
path: Iter,
) -> Option<Self> {
self.0.derive(path).map(Self)
}
@@ -357,8 +389,9 @@ macro_rules! app_crypto_public_common_if_std {
}
impl $crate::serde::Serialize for Public {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> where
S: $crate::serde::Serializer
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: $crate::serde::Serializer,
{
use $crate::Ss58Codec;
serializer.serialize_str(&self.to_ss58check())
@@ -366,15 +399,16 @@ macro_rules! app_crypto_public_common_if_std {
}
impl<'de> $crate::serde::Deserialize<'de> for Public {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error> where
D: $crate::serde::Deserializer<'de>
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: $crate::serde::Deserializer<'de>,
{
use $crate::Ss58Codec;
Public::from_ss58check(&String::deserialize(deserializer)?)
.map_err(|e| $crate::serde::de::Error::custom(format!("{:?}", e)))
}
}
}
};
}
#[cfg(not(feature = "std"))]
@@ -383,10 +417,9 @@ macro_rules! app_crypto_public_common_if_std {
macro_rules! app_crypto_public_common_if_std {
() => {
impl $crate::Derive for Public {}
}
};
}
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
/// Application-specific type whose identifier is `$key_type`.
/// can only be used together with `full_crypto` feature
@@ -418,7 +451,7 @@ macro_rules! app_crypto_signature_full_crypto {
const ID: $crate::KeyTypeId = $key_type;
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
}
}
};
}
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
@@ -448,7 +481,7 @@ macro_rules! app_crypto_signature_not_full_crypto {
const ID: $crate::KeyTypeId = $key_type;
const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type;
}
}
};
}
/// Declares Signature type which is functionally equivalent to `$sig`, but is new
@@ -461,11 +494,15 @@ macro_rules! app_crypto_signature_common {
impl $crate::Deref for Signature {
type Target = [u8];
fn deref(&self) -> &Self::Target { self.0.as_ref() }
fn deref(&self) -> &Self::Target {
self.0.as_ref()
}
}
impl AsRef<[u8]> for Signature {
fn as_ref(&self) -> &[u8] { self.0.as_ref() }
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl $crate::AppSignature for Signature {
@@ -479,7 +516,7 @@ macro_rules! app_crypto_signature_common {
Ok(<$sig>::try_from(data.as_slice())?.into())
}
}
}
};
}
/// Implement bidirectional `From` and on-way `AsRef`/`AsMut` for two types, `$inner` and `$outer`.
@@ -547,10 +584,9 @@ macro_rules! with_pair {
}
}
#[doc(hidden)]
#[macro_export]
#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))]
macro_rules! with_pair {
( $( $def:tt )* ) => {}
( $( $def:tt )* ) => {};
}
@@ -17,7 +17,7 @@
//! Sr25519 crypto types.
use crate::{RuntimePublic, KeyTypeId};
use crate::{KeyTypeId, RuntimePublic};
use sp_std::vec::Vec;
@@ -33,9 +33,9 @@ mod app {
}
}
pub use app::{Public as AppPublic, Signature as AppSignature};
#[cfg(feature = "full_crypto")]
pub use app::Pair as AppPair;
pub use app::{Public as AppPublic, Signature as AppSignature};
impl RuntimePublic for Public {
type Signature = Signature;
@@ -19,7 +19,7 @@
use sp_core::crypto::Pair;
use codec::Codec;
use sp_core::crypto::{KeyTypeId, CryptoType, CryptoTypeId, IsWrappedBy, Public};
use sp_core::crypto::{CryptoType, CryptoTypeId, IsWrappedBy, KeyTypeId, Public};
use sp_std::{fmt::Debug, vec::Vec};
/// An application-specific key.
@@ -57,7 +57,7 @@ impl<T> MaybeHash for T {}
/// Type which implements Debug and Hash in std, not when no-std (no-std variant with crypto).
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
pub trait MaybeDebugHash: sp_std::hash::Hash {}
pub trait MaybeDebugHash: sp_std::hash::Hash {}
#[cfg(all(not(feature = "std"), feature = "full_crypto"))]
impl<T: sp_std::hash::Hash> MaybeDebugHash for T {}
@@ -66,15 +66,23 @@ pub trait AppPublic:
AppKey + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec
{
/// The wrapped type which is just a plain instance of `Public`.
type Generic:
IsWrappedBy<Self> + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec;
type Generic: IsWrappedBy<Self>
+ Public
+ Ord
+ PartialOrd
+ Eq
+ PartialEq
+ Debug
+ MaybeHash
+ codec::Codec;
}
/// A application's key pair.
#[cfg(feature = "full_crypto")]
pub trait AppPair: AppKey + Pair<Public=<Self as AppKey>::Public> {
pub trait AppPair: AppKey + Pair<Public = <Self as AppKey>::Public> {
/// The wrapped type which is just a plain instance of `Pair`.
type Generic: IsWrappedBy<Self> + Pair<Public = <<Self as AppKey>::Public as AppPublic>::Generic>;
type Generic: IsWrappedBy<Self>
+ Pair<Public = <<Self as AppKey>::Public as AppPublic>::Generic>;
}
/// A application's signature.