Skip to content

Commit

Permalink
Merge pull request #11 from hicommonwealth/drew-migrations-after-staking
Browse files Browse the repository at this point in the history
Prime member selection (ElectionsPhragmen) migration
  • Loading branch information
apopiak authored Jun 29, 2020
2 parents e1ff57d + 642d385 commit 36272c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -667,6 +668,12 @@ decl_module! {
// returns the correct weight.
Self::end_block(n)
}

fn on_runtime_upgrade() -> Weight {
migration::migrate::<T>();
// TODO: Find sensible weight
0
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions frame/elections-phragmen/src/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::*;
use frame_support::{migration::{StorageKeyIterator, take_storage_item}, Twox64Concat};

pub fn migrate<T: Trait>() {
sp_runtime::print("🕊️ Migrating Election Phragmen.");
for (who, votes) in StorageKeyIterator
::<T::AccountId, Vec<T::AccountId>, Twox64Concat>
::new(b"PhragmenElection", b"VotesOf")
.drain()
{
if let Some(stake) = take_storage_item::<_, BalanceOf<T>, Twox64Concat>(b"PhragmenElection", b"StakeOf", &who) {
Voting::<T>::insert(who, (stake, votes));
}
sp_runtime::print("🕊️ Done Election Phragmen.");
}
}

0 comments on commit 36272c4

Please sign in to comment.