mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 05:31:02 +00:00
Salary pallet (#13378)
* More drafting * Paymaster pallet * Fix build * More tests * Rename * Rename * Renaming * Revert old changes * Multi-phase payouts to avoid bank-runs * Tests * Tests * Allow payment to be targeted elsewhere * Proper ssync payment failure handling * Test for repayment * Docs * Impl RankedMembers for RankedCollective * Implement Pay for Pot (i.e. basic account). * Benchmarks * Weights * Introduce Salary benchmark into node * Fix warning * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_salary * Update primitives/arithmetic/src/traits.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update frame/salary/src/lib.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update lib.rs * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Docs * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Fix * Fixes * Fixes * Move some salary traits stuff to a shared location * Fix * Update frame/salary/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/salary/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Mul floor * Fix warnings * Fix test * Docs --------- Co-authored-by: command-bot <> Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -54,7 +54,7 @@ use frame_support::{
|
||||
codec::{Decode, Encode, MaxEncodedLen},
|
||||
dispatch::{DispatchError, DispatchResultWithPostInfo, PostDispatchInfo},
|
||||
ensure,
|
||||
traits::{EnsureOrigin, PollStatus, Polling, VoteTally},
|
||||
traits::{EnsureOrigin, PollStatus, Polling, RankedMembers, VoteTally},
|
||||
CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
|
||||
};
|
||||
|
||||
@@ -472,24 +472,7 @@ pub mod pallet {
|
||||
pub fn demote_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult {
|
||||
let max_rank = T::DemoteOrigin::ensure_origin(origin)?;
|
||||
let who = T::Lookup::lookup(who)?;
|
||||
let mut record = Self::ensure_member(&who)?;
|
||||
let rank = record.rank;
|
||||
ensure!(max_rank >= rank, Error::<T, I>::NoPermission);
|
||||
|
||||
Self::remove_from_rank(&who, rank)?;
|
||||
let maybe_rank = rank.checked_sub(1);
|
||||
match maybe_rank {
|
||||
None => {
|
||||
Members::<T, I>::remove(&who);
|
||||
Self::deposit_event(Event::MemberRemoved { who, rank: 0 });
|
||||
},
|
||||
Some(rank) => {
|
||||
record.rank = rank;
|
||||
Members::<T, I>::insert(&who, &record);
|
||||
Self::deposit_event(Event::RankChanged { who, rank });
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
Self::do_demote_member(who, Some(max_rank))
|
||||
}
|
||||
|
||||
/// Remove the member entirely.
|
||||
@@ -659,7 +642,7 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Promotes a member in the ranked collective into the next role.
|
||||
/// Promotes a member in the ranked collective into the next higher rank.
|
||||
///
|
||||
/// A `maybe_max_rank` may be provided to check that the member does not get promoted beyond
|
||||
/// a certain rank. Is `None` is provided, then the rank will be incremented without checks.
|
||||
@@ -681,6 +664,33 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Demotes a member in the ranked collective into the next lower rank.
|
||||
///
|
||||
/// A `maybe_max_rank` may be provided to check that the member does not get demoted from
|
||||
/// a certain rank. Is `None` is provided, then the rank will be decremented without checks.
|
||||
fn do_demote_member(who: T::AccountId, maybe_max_rank: Option<Rank>) -> DispatchResult {
|
||||
let mut record = Self::ensure_member(&who)?;
|
||||
let rank = record.rank;
|
||||
if let Some(max_rank) = maybe_max_rank {
|
||||
ensure!(max_rank >= rank, Error::<T, I>::NoPermission);
|
||||
}
|
||||
|
||||
Self::remove_from_rank(&who, rank)?;
|
||||
let maybe_rank = rank.checked_sub(1);
|
||||
match maybe_rank {
|
||||
None => {
|
||||
Members::<T, I>::remove(&who);
|
||||
Self::deposit_event(Event::MemberRemoved { who, rank: 0 });
|
||||
},
|
||||
Some(rank) => {
|
||||
record.rank = rank;
|
||||
Members::<T, I>::insert(&who, &record);
|
||||
Self::deposit_event(Event::RankChanged { who, rank });
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a member to the rank collective, and continue to promote them until a certain rank
|
||||
/// is reached.
|
||||
pub fn do_add_member_to_rank(who: T::AccountId, rank: Rank) -> DispatchResult {
|
||||
@@ -691,4 +701,29 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> RankedMembers for Pallet<T, I> {
|
||||
type AccountId = T::AccountId;
|
||||
type Rank = Rank;
|
||||
|
||||
fn min_rank() -> Self::Rank {
|
||||
0
|
||||
}
|
||||
|
||||
fn rank_of(who: &Self::AccountId) -> Option<Self::Rank> {
|
||||
Some(Self::ensure_member(&who).ok()?.rank)
|
||||
}
|
||||
|
||||
fn induct(who: &Self::AccountId) -> DispatchResult {
|
||||
Self::do_add_member(who.clone())
|
||||
}
|
||||
|
||||
fn promote(who: &Self::AccountId) -> DispatchResult {
|
||||
Self::do_promote_member(who.clone(), None)
|
||||
}
|
||||
|
||||
fn demote(who: &Self::AccountId) -> DispatchResult {
|
||||
Self::do_demote_member(who.clone(), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user