mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 03:51:06 +00:00
Make sure that srml-collective does not initialize Members twice (#3379)
* Make sure that `srml-collective` does not initialize `Members` twice * Implement trait for `()` * Fix test
This commit is contained in:
committed by
Gavin Wood
parent
7f764dbd37
commit
0c941d66cb
@@ -24,8 +24,7 @@
|
||||
|
||||
use sr_std::prelude::*;
|
||||
use srml_support::{
|
||||
StorageValue, decl_module, decl_storage, decl_event,
|
||||
traits::{ChangeMembers}
|
||||
StorageValue, decl_module, decl_storage, decl_event, traits::{ChangeMembers, InitializeMembers},
|
||||
};
|
||||
use system::ensure_root;
|
||||
use sr_primitives::{traits::EnsureOrigin, weights::SimpleDispatchInfo};
|
||||
@@ -49,7 +48,7 @@ pub trait Trait<I=DefaultInstance>: system::Trait {
|
||||
/// The receiver of the signal for when the membership has been initialized. This happens pre-
|
||||
/// genesis and will usually be the same as `MembershipChanged`. If you need to do something
|
||||
/// different on initialization, then you can change this accordingly.
|
||||
type MembershipInitialized: ChangeMembers<Self::AccountId>;
|
||||
type MembershipInitialized: InitializeMembers<Self::AccountId>;
|
||||
|
||||
/// The receiver of the signal for when the membership has changed.
|
||||
type MembershipChanged: ChangeMembers<Self::AccountId>;
|
||||
@@ -65,12 +64,12 @@ decl_storage! {
|
||||
config(phantom): sr_std::marker::PhantomData<I>;
|
||||
build(|
|
||||
storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay),
|
||||
config: &GenesisConfig<T, I>
|
||||
config: &Self,
|
||||
| {
|
||||
sr_io::with_storage(storage, || {
|
||||
let mut members = config.members.clone();
|
||||
members.sort();
|
||||
T::MembershipInitialized::set_members_sorted(&members[..], &[]);
|
||||
T::MembershipInitialized::initialize_members(&members);
|
||||
<Members<T, I>>::put(members);
|
||||
});
|
||||
})
|
||||
@@ -266,6 +265,11 @@ mod tests {
|
||||
MEMBERS.with(|m| *m.borrow_mut() = new.to_vec());
|
||||
}
|
||||
}
|
||||
impl InitializeMembers<u64> for TestChangeMembers {
|
||||
fn initialize_members(members: &[u64]) {
|
||||
MEMBERS.with(|m| *m.borrow_mut() = members.to_vec());
|
||||
}
|
||||
}
|
||||
|
||||
impl Trait for Test {
|
||||
type Event = ();
|
||||
|
||||
Reference in New Issue
Block a user