Make Pallet ModuleId and LockIdentifier Configurable (#5695)

* transition treasury to configurable moduleids

* make election module id configurable

* convert runtime and pallet to accept module id config elections-phragmen

* add ModuleId to evm pallet

* change society pallet to configurable module id

* delete commented out module_id

* delete commented out code and merge in upstream  master

* try and convert 4 whitespace to tab

* fix remaining space to tab conversions

* trivial cleaning

* delete comment from elections-phragrems tests

* trivial

* Update frame/elections-phragmen/src/lib.rs

* add docs for elections and elections phragmen

* make has_lock test get moduleid dynamically

* Apply suggestions from code review

Co-Authored-By: Amar Singh <asinghchrony@protonmail.com>

* make sure get is imported to evm

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
This commit is contained in:
emostov
2020-04-24 02:47:32 -07:00
committed by GitHub
parent 2fb22de02e
commit 8ac2bac58d
9 changed files with 63 additions and 29 deletions
+13 -6
View File
@@ -98,8 +98,6 @@ use frame_support::{
use sp_phragmen::{build_support_map, ExtendedBalance, VoteWeight, PhragmenResult};
use frame_system::{self as system, ensure_signed, ensure_root};
const MODULE_ID: LockIdentifier = *b"phrelect";
/// The maximum votes allowed per voter.
pub const MAXIMUM_VOTE: usize = 16;
@@ -111,6 +109,9 @@ pub trait Trait: frame_system::Trait {
/// The overarching event type.c
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
/// Identifier for the elections-phragmen pallet's lock
type ModuleId: Get<LockIdentifier>;
/// The currency that people are electing with.
type Currency:
LockableCurrency<Self::AccountId, Moment=Self::BlockNumber> +
@@ -276,6 +277,7 @@ decl_module! {
const DesiredMembers: u32 = T::DesiredMembers::get();
const DesiredRunnersUp: u32 = T::DesiredRunnersUp::get();
const TermDuration: T::BlockNumber = T::TermDuration::get();
const ModuleId: LockIdentifier = T::ModuleId::get();
/// Vote for a set of candidates for the upcoming round of election.
///
@@ -321,7 +323,7 @@ decl_module! {
// lock
T::Currency::set_lock(
MODULE_ID,
T::ModuleId::get(),
&who,
locked_balance,
WithdrawReasons::except(WithdrawReason::TransactionPayment),
@@ -650,7 +652,7 @@ impl<T: Trait> Module<T> {
fn do_remove_voter(who: &T::AccountId, unreserve: bool) {
// remove storage and lock.
Voting::<T>::remove(who);
T::Currency::remove_lock(MODULE_ID, who);
T::Currency::remove_lock(T::ModuleId::get(), who);
if unreserve {
T::Currency::unreserve(who, T::VotingBond::get());
@@ -924,7 +926,7 @@ mod tests {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
}
impl pallet_balances::Trait for Test {
type Balance = u64;
@@ -1021,7 +1023,12 @@ mod tests {
}
}
parameter_types!{
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}
impl Trait for Test {
type ModuleId = ElectionsPhragmenModuleId;
type Event = Event;
type Currency = Balances;
type CurrencyToVote = CurrencyToVoteHandler;
@@ -1125,7 +1132,7 @@ mod tests {
fn has_lock(who: &u64) -> u64 {
let lock = Balances::locks(who)[0].clone();
assert_eq!(lock.id, MODULE_ID);
assert_eq!(lock.id, ElectionsPhragmenModuleId::get());
lock.amount
}