mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +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:
@@ -17,12 +17,13 @@
|
||||
|
||||
//! Migrations to version [`3.0.0`], as denoted by the changelog.
|
||||
|
||||
use codec::{Encode, Decode, FullCodec};
|
||||
use sp_std::prelude::*;
|
||||
use codec::{Decode, Encode, FullCodec};
|
||||
use frame_support::{
|
||||
RuntimeDebug, weights::Weight, Twox64Concat,
|
||||
traits::{GetPalletVersion, PalletVersion},
|
||||
weights::Weight,
|
||||
RuntimeDebug, Twox64Concat,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq)]
|
||||
struct SeatHolder<AccountId, Balance> {
|
||||
@@ -89,7 +90,7 @@ pub fn apply<T: V2ToV3>(old_voter_bond: T::Balance, old_candidacy_bond: T::Balan
|
||||
migrate_runners_up_to_recorded_deposit::<T>(old_candidacy_bond);
|
||||
migrate_members_to_recorded_deposit::<T>(old_candidacy_bond);
|
||||
Weight::max_value()
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
log::warn!(
|
||||
target: "runtime::elections-phragmen",
|
||||
@@ -103,15 +104,9 @@ pub fn apply<T: V2ToV3>(old_voter_bond: T::Balance, old_candidacy_bond: T::Balan
|
||||
|
||||
/// Migrate from the old legacy voting bond (fixed) to the new one (per-vote dynamic).
|
||||
pub fn migrate_voters_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
|
||||
<Voting<T>>::translate::<(T::Balance, Vec<T::AccountId>), _>(
|
||||
|_who, (stake, votes)| {
|
||||
Some(Voter {
|
||||
votes,
|
||||
stake,
|
||||
deposit: old_deposit,
|
||||
})
|
||||
},
|
||||
);
|
||||
<Voting<T>>::translate::<(T::Balance, Vec<T::AccountId>), _>(|_who, (stake, votes)| {
|
||||
Some(Voter { votes, stake, deposit: old_deposit })
|
||||
});
|
||||
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
@@ -122,50 +117,39 @@ pub fn migrate_voters_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
|
||||
|
||||
/// Migrate all candidates to recorded deposit.
|
||||
pub fn migrate_candidates_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
|
||||
let _ = <Candidates<T>>::translate::<Vec<T::AccountId>, _>(
|
||||
|maybe_old_candidates| {
|
||||
maybe_old_candidates.map(|old_candidates| {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
"migrated {} candidate accounts.",
|
||||
old_candidates.len(),
|
||||
);
|
||||
old_candidates
|
||||
.into_iter()
|
||||
.map(|c| (c, old_deposit))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
},
|
||||
);
|
||||
let _ = <Candidates<T>>::translate::<Vec<T::AccountId>, _>(|maybe_old_candidates| {
|
||||
maybe_old_candidates.map(|old_candidates| {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
"migrated {} candidate accounts.",
|
||||
old_candidates.len(),
|
||||
);
|
||||
old_candidates.into_iter().map(|c| (c, old_deposit)).collect::<Vec<_>>()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/// Migrate all members to recorded deposit.
|
||||
pub fn migrate_members_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
|
||||
let _ = <Members<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(
|
||||
|maybe_old_members| {
|
||||
maybe_old_members.map(|old_members| {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
"migrated {} member accounts.",
|
||||
old_members.len(),
|
||||
);
|
||||
old_members
|
||||
.into_iter()
|
||||
.map(|(who, stake)| SeatHolder {
|
||||
who,
|
||||
stake,
|
||||
deposit: old_deposit,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
},
|
||||
);
|
||||
let _ = <Members<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(|maybe_old_members| {
|
||||
maybe_old_members.map(|old_members| {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
"migrated {} member accounts.",
|
||||
old_members.len(),
|
||||
);
|
||||
old_members
|
||||
.into_iter()
|
||||
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/// Migrate all runners-up to recorded deposit.
|
||||
pub fn migrate_runners_up_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
|
||||
let _ = <RunnersUp<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(
|
||||
|maybe_old_runners_up| {
|
||||
let _ =
|
||||
<RunnersUp<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(|maybe_old_runners_up| {
|
||||
maybe_old_runners_up.map(|old_runners_up| {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
@@ -174,13 +158,8 @@ pub fn migrate_runners_up_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance
|
||||
);
|
||||
old_runners_up
|
||||
.into_iter()
|
||||
.map(|(who, stake)| SeatHolder {
|
||||
who,
|
||||
stake,
|
||||
deposit: old_deposit,
|
||||
})
|
||||
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
//! Migrations to version [`4.0.0`], as denoted by the changelog.
|
||||
|
||||
use frame_support::{
|
||||
traits::{Get, GetPalletVersion, PalletVersion},
|
||||
weights::Weight,
|
||||
traits::{GetPalletVersion, PalletVersion, Get},
|
||||
};
|
||||
|
||||
/// The old prefix.
|
||||
@@ -32,17 +32,15 @@ pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
|
||||
/// `<Runtime as frame_system::Config>::PalletInfo::name::<ElectionsPhragmenPallet>`.
|
||||
///
|
||||
/// The old storage prefix, `PhragmenElection` is hardcoded in the migration code.
|
||||
pub fn migrate<
|
||||
T: frame_system::Config,
|
||||
P: GetPalletVersion,
|
||||
N: AsRef<str>,
|
||||
>(new_pallet_name: N) -> Weight {
|
||||
pub fn migrate<T: frame_system::Config, P: GetPalletVersion, N: AsRef<str>>(
|
||||
new_pallet_name: N,
|
||||
) -> Weight {
|
||||
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
|
||||
log::info!(
|
||||
target: "runtime::elections-phragmen",
|
||||
"New pallet name is equal to the old prefix. No migration needs to be done.",
|
||||
);
|
||||
return 0;
|
||||
return 0
|
||||
}
|
||||
let maybe_storage_version = <P as GetPalletVersion>::storage_version();
|
||||
log::info!(
|
||||
@@ -59,7 +57,7 @@ pub fn migrate<
|
||||
new_pallet_name.as_ref().as_bytes(),
|
||||
);
|
||||
<T as frame_system::Config>::BlockWeights::get().max_block
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
log::warn!(
|
||||
target: "runtime::elections-phragmen",
|
||||
@@ -103,7 +101,7 @@ pub fn pre_migration<P: GetPalletVersion, N: AsRef<str>>(new: N) {
|
||||
/// [`frame_support::traits::OnRuntimeUpgrade::post_upgrade`] for further testing.
|
||||
///
|
||||
/// Panics if anything goes wrong.
|
||||
pub fn post_migration<P : GetPalletVersion>() {
|
||||
pub fn post_migration<P: GetPalletVersion>() {
|
||||
log::info!("post-migration elections-phragmen");
|
||||
// ensure we've been updated to v4 by the automatic write of crate version -> storage version.
|
||||
assert!(<P as GetPalletVersion>::storage_version().unwrap().major == 4);
|
||||
|
||||
Reference in New Issue
Block a user