Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Pay trait gets Error item #14258

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions frame/salary/src/lib.rs
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion frame/salary/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ impl Pay for TestPay {
type Balance = u64;
type Id = u64;
type AssetKind = ();
type Error = ();

fn pay(
who: &Self::Beneficiary,
_: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()> {
) -> Result<Self::Id, Self::Error> {
PAID.with(|paid| *paid.borrow_mut().entry(*who).or_default() += amount);
Ok(LAST_ID.with(|lid| {
let x = *lid.borrow();
Expand Down
10 changes: 7 additions & 3 deletions frame/support/src/traits/tokens/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::{RuntimeDebug, TypedGet};
use sp_runtime::DispatchError;
use sp_std::fmt::Debug;

use super::{fungible, Balance, Preservation::Expendable};
Expand All @@ -38,13 +39,15 @@ pub trait Pay {
type AssetKind;
/// An identifier given to an individual payment.
type Id: FullCodec + MaxEncodedLen + TypeInfo + Clone + Eq + PartialEq + Debug + Copy;
/// An error which could be returned by the Pay type
type Error: Debug;
/// 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::Beneficiary,
asset_kind: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()>;
) -> Result<Self::Id, Self::Error>;
/// Check how a payment has proceeded. `id` must have been previously returned by `pay` for
/// the result of this call to be meaningful. Once this returns anything other than
/// `InProgress` for some `id` it must return `Unknown` rather than the actual result
Expand Down Expand Up @@ -81,12 +84,13 @@ impl<A: TypedGet, F: fungible::Mutate<A::Type>> Pay for PayFromAccount<F, A> {
type Beneficiary = A::Type;
type AssetKind = ();
type Id = ();
type Error = DispatchError;
fn pay(
who: &Self::Beneficiary,
_: Self::AssetKind,
amount: Self::Balance,
) -> Result<Self::Id, ()> {
<F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable).map_err(|_| ())?;
) -> Result<Self::Id, Self::Error> {
<F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable)?;
Ok(())
}
fn check_payment(_: ()) -> PaymentStatus {
Expand Down