mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
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:
@@ -37,20 +37,22 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
Parameter, traits::{Get, FindAuthor, OneSessionHandler, OnTimestampSet}, ConsensusEngineId,
|
||||
traits::{FindAuthor, Get, OnTimestampSet, OneSessionHandler},
|
||||
ConsensusEngineId, Parameter,
|
||||
};
|
||||
use sp_consensus_aura::{AuthorityIndex, ConsensusLog, Slot, AURA_ENGINE_ID};
|
||||
use sp_runtime::{
|
||||
generic::DigestItem,
|
||||
traits::{IsMember, Member, SaturatedConversion, Saturating, Zero},
|
||||
RuntimeAppPublic,
|
||||
traits::{SaturatedConversion, Saturating, Zero, Member, IsMember}, generic::DigestItem,
|
||||
};
|
||||
use sp_consensus_aura::{AURA_ENGINE_ID, ConsensusLog, AuthorityIndex, Slot};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
pub mod migrations;
|
||||
mod mock;
|
||||
mod tests;
|
||||
pub mod migrations;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
@@ -63,7 +65,11 @@ pub mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: pallet_timestamp::Config + frame_system::Config {
|
||||
/// The identifier type for an authority.
|
||||
type AuthorityId: Member + Parameter + RuntimeAppPublic + Default + MaybeSerializeDeserialize;
|
||||
type AuthorityId: Member
|
||||
+ Parameter
|
||||
+ RuntimeAppPublic
|
||||
+ Default
|
||||
+ MaybeSerializeDeserialize;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
@@ -123,10 +129,8 @@ impl<T: Config> Pallet<T> {
|
||||
fn change_authorities(new: Vec<T::AuthorityId>) {
|
||||
<Authorities<T>>::put(&new);
|
||||
|
||||
let log: DigestItem<T::Hash> = DigestItem::Consensus(
|
||||
AURA_ENGINE_ID,
|
||||
ConsensusLog::AuthoritiesChange(new).encode()
|
||||
);
|
||||
let log: DigestItem<T::Hash> =
|
||||
DigestItem::Consensus(AURA_ENGINE_ID, ConsensusLog::AuthoritiesChange(new).encode());
|
||||
<frame_system::Pallet<T>>::deposit_log(log.into());
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ impl<T: Config> Pallet<T> {
|
||||
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
|
||||
for (id, mut data) in pre_runtime_digests {
|
||||
if id == AURA_ENGINE_ID {
|
||||
return Slot::decode(&mut data).ok();
|
||||
return Slot::decode(&mut data).ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,14 +170,16 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
|
||||
type Key = T::AuthorityId;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, T::AuthorityId)>
|
||||
where
|
||||
I: Iterator<Item = (&'a T::AccountId, T::AuthorityId)>,
|
||||
{
|
||||
let authorities = validators.map(|(_, k)| k).collect::<Vec<_>>();
|
||||
Self::initialize_authorities(&authorities);
|
||||
}
|
||||
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, T::AuthorityId)>
|
||||
where
|
||||
I: Iterator<Item = (&'a T::AccountId, T::AuthorityId)>,
|
||||
{
|
||||
// instant changes
|
||||
if changed {
|
||||
@@ -196,8 +202,9 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
|
||||
}
|
||||
|
||||
impl<T: Config> FindAuthor<u32> for Pallet<T> {
|
||||
fn find_author<'a, I>(digests: I) -> Option<u32> where
|
||||
I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
|
||||
fn find_author<'a, I>(digests: I) -> Option<u32>
|
||||
where
|
||||
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
|
||||
{
|
||||
for (id, mut data) in digests.into_iter() {
|
||||
if id == AURA_ENGINE_ID {
|
||||
@@ -220,7 +227,8 @@ impl<T: Config, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
|
||||
for FindAccountFromAuthorIndex<T, Inner>
|
||||
{
|
||||
fn find_author<'a, I>(digests: I) -> Option<T::AuthorityId>
|
||||
where I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>
|
||||
where
|
||||
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
|
||||
{
|
||||
let i = Inner::find_author(digests)?;
|
||||
|
||||
@@ -234,9 +242,7 @@ pub type AuraAuthorId<T> = FindAccountFromAuthorIndex<T, Pallet<T>>;
|
||||
|
||||
impl<T: Config> IsMember<T::AuthorityId> for Pallet<T> {
|
||||
fn is_member(authority_id: &T::AuthorityId) -> bool {
|
||||
Self::authorities()
|
||||
.iter()
|
||||
.any(|id| id == authority_id)
|
||||
Self::authorities().iter().any(|id| id == authority_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +254,9 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
|
||||
let timestamp_slot = moment / slot_duration;
|
||||
let timestamp_slot = Slot::from(timestamp_slot.saturated_into::<u64>());
|
||||
|
||||
assert!(CurrentSlot::<T>::get() == timestamp_slot, "Timestamp slot must match `CurrentSlot`");
|
||||
assert!(
|
||||
CurrentSlot::<T>::get() == timestamp_slot,
|
||||
"Timestamp slot must match `CurrentSlot`"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
|
||||
//! Migrations for the AURA pallet.
|
||||
|
||||
use frame_support::{traits::Get, weights::Weight, pallet_prelude::*};
|
||||
use frame_support::{pallet_prelude::*, traits::Get, weights::Weight};
|
||||
|
||||
struct __LastTimestamp<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: RemoveLastTimestamp> frame_support::traits::StorageInstance for __LastTimestamp<T> {
|
||||
fn pallet_prefix() -> &'static str { T::PalletPrefix::get() }
|
||||
fn pallet_prefix() -> &'static str {
|
||||
T::PalletPrefix::get()
|
||||
}
|
||||
const STORAGE_PREFIX: &'static str = "LastTimestamp";
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,13 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use crate as pallet_aura;
|
||||
use sp_consensus_aura::ed25519::AuthorityId;
|
||||
use sp_runtime::{traits::IdentityLookup, testing::{Header, UintAuthorityId}};
|
||||
use frame_support::{parameter_types, traits::GenesisBuild};
|
||||
use sp_consensus_aura::ed25519::AuthorityId;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::{Header, UintAuthorityId},
|
||||
traits::IdentityLookup,
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -86,8 +89,10 @@ impl pallet_aura::Config for Test {
|
||||
|
||||
pub fn new_test_ext(authorities: Vec<u64>) -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_aura::GenesisConfig::<Test>{
|
||||
pallet_aura::GenesisConfig::<Test> {
|
||||
authorities: authorities.into_iter().map(|a| UintAuthorityId(a).to_public_key()).collect(),
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::mock::{Aura, new_test_ext};
|
||||
use crate::mock::{new_test_ext, Aura};
|
||||
|
||||
#[test]
|
||||
fn initial_values() {
|
||||
|
||||
Reference in New Issue
Block a user