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

Commit e1c1b22

Browse files
authored
Pay trait gets Error item (#14258)
* `Pay` trait gets `Error` item * Formatting
1 parent f47a84a commit e1c1b22

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

frame/salary/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ pub mod pallet {
436436

437437
claimant.last_active = status.cycle_index;
438438

439-
let id = T::Paymaster::pay(&beneficiary, (), payout)
440-
.map_err(|()| Error::<T, I>::PayError)?;
439+
let id =
440+
T::Paymaster::pay(&beneficiary, (), payout).map_err(|_| Error::<T, I>::PayError)?;
441441

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

frame/salary/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ impl Pay for TestPay {
103103
type Balance = u64;
104104
type Id = u64;
105105
type AssetKind = ();
106+
type Error = ();
106107

107108
fn pay(
108109
who: &Self::Beneficiary,
109110
_: Self::AssetKind,
110111
amount: Self::Balance,
111-
) -> Result<Self::Id, ()> {
112+
) -> Result<Self::Id, Self::Error> {
112113
PAID.with(|paid| *paid.borrow_mut().entry(*who).or_default() += amount);
113114
Ok(LAST_ID.with(|lid| {
114115
let x = *lid.borrow();

frame/support/src/traits/tokens/pay.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
2121
use scale_info::TypeInfo;
2222
use sp_core::{RuntimeDebug, TypedGet};
23+
use sp_runtime::DispatchError;
2324
use sp_std::fmt::Debug;
2425

2526
use super::{fungible, Balance, Preservation::Expendable};
@@ -38,13 +39,15 @@ pub trait Pay {
3839
type AssetKind;
3940
/// An identifier given to an individual payment.
4041
type Id: FullCodec + MaxEncodedLen + TypeInfo + Clone + Eq + PartialEq + Debug + Copy;
42+
/// An error which could be returned by the Pay type
43+
type Error: Debug;
4144
/// Make a payment and return an identifier for later evaluation of success in some off-chain
4245
/// mechanism (likely an event, but possibly not on this chain).
4346
fn pay(
4447
who: &Self::Beneficiary,
4548
asset_kind: Self::AssetKind,
4649
amount: Self::Balance,
47-
) -> Result<Self::Id, ()>;
50+
) -> Result<Self::Id, Self::Error>;
4851
/// Check how a payment has proceeded. `id` must have been previously returned by `pay` for
4952
/// the result of this call to be meaningful. Once this returns anything other than
5053
/// `InProgress` for some `id` it must return `Unknown` rather than the actual result
@@ -81,12 +84,13 @@ impl<A: TypedGet, F: fungible::Mutate<A::Type>> Pay for PayFromAccount<F, A> {
8184
type Beneficiary = A::Type;
8285
type AssetKind = ();
8386
type Id = ();
87+
type Error = DispatchError;
8488
fn pay(
8589
who: &Self::Beneficiary,
8690
_: Self::AssetKind,
8791
amount: Self::Balance,
88-
) -> Result<Self::Id, ()> {
89-
<F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable).map_err(|_| ())?;
92+
) -> Result<Self::Id, Self::Error> {
93+
<F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable)?;
9094
Ok(())
9195
}
9296
fn check_payment(_: ()) -> PaymentStatus {

0 commit comments

Comments
 (0)