helper macro to create storage types on the fly (#8456)

* helper macro to create storage types on the fly

* Update frame/support/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* update lock

* fix test;

* Fix line width

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Kian Paimani
2021-03-30 11:40:56 +02:00
committed by GitHub
parent 217c4be226
commit 19f9224e5d
3 changed files with 140 additions and 55 deletions
+7 -22
View File
@@ -1036,30 +1036,15 @@ pub mod migrations {
pub mod v6 {
use super::*;
use frame_support::{traits::Get, weights::Weight, pallet_prelude::*};
macro_rules! generate_storage_types {
($name:ident => Value<$value:ty>) => {
paste::paste! {
struct [<$name Instance>];
impl frame_support::traits::StorageInstance for [<$name Instance>] {
fn pallet_prefix() -> &'static str {
"Staking"
}
const STORAGE_PREFIX: &'static str = stringify!($name);
}
type $name = StorageValue<[<$name Instance>], $value, ValueQuery>;
}
}
}
use frame_support::{traits::Get, weights::Weight, generate_storage_alias};
// NOTE: value type doesn't matter, we just set it to () here.
generate_storage_types!(SnapshotValidators => Value<()>);
generate_storage_types!(SnapshotNominators => Value<()>);
generate_storage_types!(QueuedElected => Value<()>);
generate_storage_types!(QueuedScore => Value<()>);
generate_storage_types!(EraElectionStatus => Value<()>);
generate_storage_types!(IsCurrentSessionFinal => Value<()>);
generate_storage_alias!(Staking, SnapshotValidators => Value<()>);
generate_storage_alias!(Staking, SnapshotNominators => Value<()>);
generate_storage_alias!(Staking, QueuedElected => Value<()>);
generate_storage_alias!(Staking, QueuedScore => Value<()>);
generate_storage_alias!(Staking, EraElectionStatus => Value<()>);
generate_storage_alias!(Staking, IsCurrentSessionFinal => Value<()>);
/// check to execute prior to migration.
pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {