diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index a483273615506..adb57253799a2 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -105,6 +105,7 @@ use frame_system::{self as system, ensure_signed, ensure_root}; use frame_support::traits::MigrateAccount; mod benchmarking; +mod migration; /// The maximum votes allowed per voter. pub const MAXIMUM_VOTE: usize = 16; @@ -667,6 +668,12 @@ decl_module! { // returns the correct weight. Self::end_block(n) } + + fn on_runtime_upgrade() -> Weight { + migration::migrate::(); + // TODO: Find sensible weight + 0 + } } } diff --git a/frame/elections-phragmen/src/migration.rs b/frame/elections-phragmen/src/migration.rs new file mode 100644 index 0000000000000..1befa09a7a576 --- /dev/null +++ b/frame/elections-phragmen/src/migration.rs @@ -0,0 +1,16 @@ +use super::*; +use frame_support::{migration::{StorageKeyIterator, take_storage_item}, Twox64Concat}; + +pub fn migrate() { + sp_runtime::print("🕊️ Migrating Election Phragmen."); + for (who, votes) in StorageKeyIterator + ::, Twox64Concat> + ::new(b"PhragmenElection", b"VotesOf") + .drain() + { + if let Some(stake) = take_storage_item::<_, BalanceOf, Twox64Concat>(b"PhragmenElection", b"StakeOf", &who) { + Voting::::insert(who, (stake, votes)); + } + sp_runtime::print("🕊️ Done Election Phragmen."); + } +} \ No newline at end of file