mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 23:57:56 +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:
@@ -36,7 +36,7 @@ pub use members::{AllowAll, DenyAll, Filter};
|
||||
pub use members::{
|
||||
AsContains, ChangeMembers, Contains, ContainsLengthBound, ContainsPair, Everything,
|
||||
EverythingBut, FromContainsPair, InitializeMembers, InsideBoth, IsInVec, Nothing,
|
||||
SortedMembers, TheseExcept,
|
||||
RankedMembers, SortedMembers, TheseExcept,
|
||||
};
|
||||
|
||||
mod validation;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
//! Traits for dealing with the idea of membership.
|
||||
|
||||
use impl_trait_for_tuples::impl_for_tuples;
|
||||
use sp_arithmetic::traits::AtLeast16BitUnsigned;
|
||||
use sp_runtime::DispatchResult;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
/// A trait for querying whether a type can be said to "contain" a value.
|
||||
@@ -265,6 +267,28 @@ pub trait ContainsLengthBound {
|
||||
fn max_len() -> usize;
|
||||
}
|
||||
|
||||
/// Ranked membership data structure.
|
||||
pub trait RankedMembers {
|
||||
type AccountId;
|
||||
type Rank: AtLeast16BitUnsigned;
|
||||
|
||||
/// The lowest rank possible in this membership organisation.
|
||||
fn min_rank() -> Self::Rank;
|
||||
|
||||
/// Return the rank of the given ID, or `None` if they are not a member.
|
||||
fn rank_of(who: &Self::AccountId) -> Option<Self::Rank>;
|
||||
|
||||
/// Add a member to the group at the `min_rank()`.
|
||||
fn induct(who: &Self::AccountId) -> DispatchResult;
|
||||
|
||||
/// Promote a member to the next higher rank.
|
||||
fn promote(who: &Self::AccountId) -> DispatchResult;
|
||||
|
||||
/// Demote a member to the next lower rank; demoting beyond the `min_rank` removes the
|
||||
/// member entirely.
|
||||
fn demote(who: &Self::AccountId) -> DispatchResult;
|
||||
}
|
||||
|
||||
/// Trait for type that can handle the initialization of account IDs at genesis.
|
||||
pub trait InitializeMembers<AccountId> {
|
||||
/// Initialize the members to the given `members`.
|
||||
|
||||
@@ -28,6 +28,7 @@ pub mod nonfungibles;
|
||||
pub mod nonfungibles_v2;
|
||||
pub use imbalance::Imbalance;
|
||||
pub use misc::{
|
||||
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, DepositConsequence,
|
||||
ExistenceRequirement, Locker, WithdrawConsequence, WithdrawReasons,
|
||||
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, ConvertRank,
|
||||
DepositConsequence, ExistenceRequirement, GetSalary, Locker, WithdrawConsequence,
|
||||
WithdrawReasons,
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
|
||||
use sp_arithmetic::traits::{AtLeast32BitUnsigned, Zero};
|
||||
use sp_core::RuntimeDebug;
|
||||
use sp_runtime::{ArithmeticError, DispatchError, TokenError};
|
||||
use sp_runtime::{traits::Convert, ArithmeticError, DispatchError, TokenError};
|
||||
use sp_std::fmt::Debug;
|
||||
|
||||
/// One of a number of consequences of withdrawing a fungible from an account.
|
||||
@@ -225,3 +225,18 @@ impl<CollectionId, ItemId> Locker<CollectionId, ItemId> for () {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieve the salary for a member of a particular rank.
|
||||
pub trait GetSalary<Rank, AccountId, Balance> {
|
||||
/// Retrieve the salary for a given rank. The account ID is also supplied in case this changes
|
||||
/// things.
|
||||
fn get_salary(rank: Rank, who: &AccountId) -> Balance;
|
||||
}
|
||||
|
||||
/// Adapter for a rank-to-salary `Convert` implementation into a `GetSalary` implementation.
|
||||
pub struct ConvertRank<C>(sp_std::marker::PhantomData<C>);
|
||||
impl<A, R, B, C: Convert<R, B>> GetSalary<R, A, B> for ConvertRank<C> {
|
||||
fn get_salary(rank: R, _: &A) -> B {
|
||||
C::convert(rank)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user