mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Introduce default-setting prime for collective (#5137)
* Introduce default-setting prime for collective * Docs. * Elections phragmen supports prime * Fix * Membership supports prime * Fix * Update frame/collective/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -91,6 +91,14 @@ impl<T: FullCodec, G: StorageValue<T>> storage::StorageValue<T> for G {
|
||||
unhashed::put(&Self::storage_value_final_key(), &val)
|
||||
}
|
||||
|
||||
fn set(maybe_val: Self::Query) {
|
||||
if let Some(val) = G::from_query_to_optional_value(maybe_val) {
|
||||
unhashed::put(&Self::storage_value_final_key(), &val)
|
||||
} else {
|
||||
unhashed::kill(&Self::storage_value_final_key())
|
||||
}
|
||||
}
|
||||
|
||||
fn kill() {
|
||||
unhashed::kill(&Self::storage_value_final_key())
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ pub trait StorageValue<T: FullCodec> {
|
||||
/// Store a value under this key into the provided storage instance.
|
||||
fn put<Arg: EncodeLike<T>>(val: Arg);
|
||||
|
||||
/// Store a value under this key into the provided storage instance; this uses the query
|
||||
/// type rather than the underlying value.
|
||||
fn set(val: Self::Query);
|
||||
|
||||
/// Mutate the value
|
||||
fn mutate<R, F: FnOnce(&mut Self::Query) -> R>(f: F) -> R;
|
||||
|
||||
|
||||
@@ -808,6 +808,8 @@ impl WithdrawReasons {
|
||||
pub trait ChangeMembers<AccountId: Clone + Ord> {
|
||||
/// A number of members `incoming` just joined the set and replaced some `outgoing` ones. The
|
||||
/// new set is given by `new`, and need not be sorted.
|
||||
///
|
||||
/// This resets any previous value of prime.
|
||||
fn change_members(incoming: &[AccountId], outgoing: &[AccountId], mut new: Vec<AccountId>) {
|
||||
new.sort_unstable();
|
||||
Self::change_members_sorted(incoming, outgoing, &new[..]);
|
||||
@@ -817,6 +819,8 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
|
||||
/// new set is thus given by `sorted_new` and **must be sorted**.
|
||||
///
|
||||
/// NOTE: This is the only function that needs to be implemented in `ChangeMembers`.
|
||||
///
|
||||
/// This resets any previous value of prime.
|
||||
fn change_members_sorted(
|
||||
incoming: &[AccountId],
|
||||
outgoing: &[AccountId],
|
||||
@@ -825,6 +829,8 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
|
||||
|
||||
/// Set the new members; they **must already be sorted**. This will compute the diff and use it to
|
||||
/// call `change_members_sorted`.
|
||||
///
|
||||
/// This resets any previous value of prime.
|
||||
fn set_members_sorted(new_members: &[AccountId], old_members: &[AccountId]) {
|
||||
let (incoming, outgoing) = Self::compute_members_diff(new_members, old_members);
|
||||
Self::change_members_sorted(&incoming[..], &outgoing[..], &new_members);
|
||||
@@ -865,14 +871,20 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
|
||||
}
|
||||
(incoming, outgoing)
|
||||
}
|
||||
|
||||
/// Set the prime member.
|
||||
fn set_prime(_prime: Option<AccountId>) {}
|
||||
}
|
||||
|
||||
impl<T: Clone + Ord> ChangeMembers<T> for () {
|
||||
fn change_members(_: &[T], _: &[T], _: Vec<T>) {}
|
||||
fn change_members_sorted(_: &[T], _: &[T], _: &[T]) {}
|
||||
fn set_members_sorted(_: &[T], _: &[T]) {}
|
||||
fn set_prime(_: Option<T>) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Trait for type that can handle the initialization of account IDs at genesis.
|
||||
pub trait InitializeMembers<AccountId> {
|
||||
/// Initialize the members to the given `members`.
|
||||
|
||||
Reference in New Issue
Block a user