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
+9 -6
View File
@@ -33,7 +33,7 @@ use frame_support::{
weights::{Weight, MINIMUM_WEIGHT, DispatchClass},
traits::{
Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier, BalanceStatus,
OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers
OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers,
}
};
use codec::{Encode, Decode};
@@ -126,8 +126,6 @@ pub enum CellStatus {
Hole,
}
const MODULE_ID: LockIdentifier = *b"py/elect";
/// Number of voters grouped in one chunk.
pub const VOTER_SET_SIZE: usize = 64;
/// NUmber of approvals grouped in one chunk.
@@ -149,6 +147,9 @@ const APPROVAL_FLAG_LEN: usize = 32;
pub trait Trait: frame_system::Trait {
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
/// Identifier for the elections pallet's lock
type ModuleId: Get<LockIdentifier>;
/// The currency that people are electing with.
type Currency:
LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>
@@ -379,6 +380,8 @@ decl_module! {
/// The chunk size of the approval vector.
const APPROVAL_SET_SIZE: u32 = APPROVAL_SET_SIZE as u32;
const ModuleId: LockIdentifier = T::ModuleId::get();
fn deposit_event() = default;
/// Set candidate approvals. Approval slots stay valid as long as candidates in those slots
@@ -494,7 +497,7 @@ decl_module! {
);
T::Currency::remove_lock(
MODULE_ID,
T::ModuleId::get(),
if valid { &who } else { &reporter }
);
@@ -532,7 +535,7 @@ decl_module! {
Self::remove_voter(&who, index);
T::Currency::unreserve(&who, T::VotingBond::get());
T::Currency::remove_lock(MODULE_ID, &who);
T::Currency::remove_lock(T::ModuleId::get(), &who);
}
/// Submit oneself for candidacy.
@@ -892,7 +895,7 @@ impl<T: Trait> Module<T> {
}
T::Currency::set_lock(
MODULE_ID,
T::ModuleId::get(),
&who,
locked_balance,
WithdrawReasons::all(),
+6 -1
View File
@@ -21,7 +21,7 @@
use std::cell::RefCell;
use frame_support::{
StorageValue, StorageMap, parameter_types, assert_ok,
traits::{Get, ChangeMembers, Currency},
traits::{Get, ChangeMembers, Currency, LockIdentifier},
weights::Weight,
};
use sp_core::H256;
@@ -122,6 +122,10 @@ impl ChangeMembers<u64> for TestChangeMembers {
}
}
parameter_types!{
pub const ElectionModuleId: LockIdentifier = *b"py/elect";
}
impl elections::Trait for Test {
type Event = Event;
type Currency = Balances;
@@ -139,6 +143,7 @@ impl elections::Trait for Test {
type InactiveGracePeriod = InactiveGracePeriod;
type VotingPeriod = VotingPeriod;
type DecayRatio = DecayRatio;
type ModuleId = ElectionModuleId;
}
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;