Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename and add missing
  • Loading branch information
franciscoaguirre committed Mar 15, 2023
commit b0c04d6c529d5388ac2f3930ea206bb51afc5fc7
6 changes: 3 additions & 3 deletions frame/salary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub mod pallet {

/// Means by which we can make payments to accounts. This also defines the currency and the
/// balance which we use to denote that currency.
type Paymaster: Pay<AccountId = <Self as frame_system::Config>::AccountId>;
type Paymaster: Pay<Beneficiary = <Self as frame_system::Config>::AccountId, AssetKind = ()>;

/// The current membership of payees.
type Members: RankedMembers<AccountId = <Self as frame_system::Config>::AccountId>;
Expand Down Expand Up @@ -436,8 +436,8 @@ pub mod pallet {

claimant.last_active = status.cycle_index;

let id =
T::Paymaster::pay(&beneficiary, payout).map_err(|()| Error::<T, I>::PayError)?;
let id = T::Paymaster::pay(&beneficiary, (), payout)
.map_err(|()| Error::<T, I>::PayError)?;

claimant.status = Attempted { registered, id, amount: payout };

Expand Down
12 changes: 8 additions & 4 deletions frame/salary/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ fn set_status(id: u64, s: PaymentStatus) {

pub struct TestPay;
impl Pay for TestPay {
type AccountId = u64;
type Beneficiary = u64;
type Balance = u64;
type Id = u64;
type AssetId = ();
type AssetKind = ();

fn pay(who: &Self::AccountId, amount: Self::Balance) -> Result<Self::Id, ()> {
fn pay(
who: &Self::Beneficiary,
_: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()> {
PAID.with(|paid| *paid.borrow_mut().entry(*who).or_default() += amount);
Ok(LAST_ID.with(|lid| {
let x = *lid.borrow();
Expand All @@ -116,7 +120,7 @@ impl Pay for TestPay {
STATUS.with(|s| s.borrow().get(&id).cloned().unwrap_or(PaymentStatus::Unknown))
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(_: &Self::AccountId, _: Self::Balance) {}
fn ensure_successful(_: &Self::Beneficiary, _: Self::Balance) {}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_concluded(id: Self::Id) {
set_status(id, PaymentStatus::Failure)
Expand Down
30 changes: 19 additions & 11 deletions frame/support/src/traits/tokens/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ use super::{fungible, Balance};
pub trait Pay {
/// The type by which we measure units of the currency in which we make payments.
type Balance: Balance;
/// The type by which we identify the individuals to whom a payment may be made.
type AccountId;
/// The type of the asset that is going to be paid, `()` for native asset
type AssetId;
/// The type by which we identify the beneficiaries to whom a payment may be made.
type Beneficiary;
/// The kind of asset that is going to be paid, `()` for native asset
type AssetKind;
/// An identifier given to an individual payment.
type Id: FullCodec + MaxEncodedLen + TypeInfo + Clone + Eq + PartialEq + Debug + Copy;
/// Make a payment and return an identifier for later evaluation of success in some off-chain
/// mechanism (likely an event, but possibly not on this chain).
fn pay(who: &Self::AccountId, amount: Self::Balance) -> Result<Self::Id, ()>;
/// Check how a payment has proceeded. `id` must have been a previously returned by `pay` for
fn pay(
who: &Self::Beneficiary,
asset_kind: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()>;
/// Check how a payment has proceeded. `id` must have been previously returned by `pay` for
/// the result of this call to be meaningful.
fn check_payment(id: Self::Id) -> PaymentStatus;
/// Ensure that a call to pay with the given parameters will be successful if done immediately
/// after this call. Used in benchmarking code.
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(who: &Self::AccountId, amount: Self::Balance);
fn ensure_successful(who: &Self::Beneficiary, amount: Self::Balance);
/// Ensure that a call to `check_payment` with the given parameters will return either `Success`
/// or `Failure`.
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -70,18 +74,22 @@ impl<A: TypedGet, F: fungible::Transfer<A::Type> + fungible::Mutate<A::Type>> Pa
for PayFromAccount<F, A>
{
type Balance = F::Balance;
type AccountId = A::Type;
type AssetId = ();
type Beneficiary = A::Type;
type AssetKind = ();
type Id = ();
fn pay(who: &Self::AccountId, amount: Self::Balance) -> Result<Self::Id, ()> {
fn pay(
who: &Self::Beneficiary,
_: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()> {
<F as fungible::Transfer<_>>::transfer(&A::get(), who, amount, false).map_err(|_| ())?;
Ok(())
}
fn check_payment(_: ()) -> PaymentStatus {
PaymentStatus::Success
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_successful(_: &Self::AccountId, amount: Self::Balance) {
fn ensure_successful(_: &Self::Beneficiary, amount: Self::Balance) {
<F as fungible::Mutate<_>>::mint_into(&A::get(), amount).unwrap();
}
#[cfg(feature = "runtime-benchmarks")]
Expand Down