Pay trait gets Error item (#14258)

* `Pay` trait gets `Error` item

* Formatting
This commit is contained in:
Gavin Wood
2023-05-29 15:29:51 +01:00
committed by GitHub
parent cb533ffa98
commit c40a4cc139
3 changed files with 11 additions and 6 deletions
+2 -2
View File
@@ -436,8 +436,8 @@ pub mod pallet {
claimant.last_active = status.cycle_index; claimant.last_active = status.cycle_index;
let id = T::Paymaster::pay(&beneficiary, (), payout) let id =
.map_err(|()| Error::<T, I>::PayError)?; T::Paymaster::pay(&beneficiary, (), payout).map_err(|_| Error::<T, I>::PayError)?;
claimant.status = Attempted { registered, id, amount: payout }; claimant.status = Attempted { registered, id, amount: payout };
+2 -1
View File
@@ -103,12 +103,13 @@ impl Pay for TestPay {
type Balance = u64; type Balance = u64;
type Id = u64; type Id = u64;
type AssetKind = (); type AssetKind = ();
type Error = ();
fn pay( fn pay(
who: &Self::Beneficiary, who: &Self::Beneficiary,
_: Self::AssetKind, _: Self::AssetKind,
amount: Self::Balance, amount: Self::Balance,
) -> Result<Self::Id, ()> { ) -> Result<Self::Id, Self::Error> {
PAID.with(|paid| *paid.borrow_mut().entry(*who).or_default() += amount); PAID.with(|paid| *paid.borrow_mut().entry(*who).or_default() += amount);
Ok(LAST_ID.with(|lid| { Ok(LAST_ID.with(|lid| {
let x = *lid.borrow(); let x = *lid.borrow();
@@ -20,6 +20,7 @@
use codec::{Decode, Encode, FullCodec, MaxEncodedLen}; use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use scale_info::TypeInfo; use scale_info::TypeInfo;
use sp_core::{RuntimeDebug, TypedGet}; use sp_core::{RuntimeDebug, TypedGet};
use sp_runtime::DispatchError;
use sp_std::fmt::Debug; use sp_std::fmt::Debug;
use super::{fungible, Balance, Preservation::Expendable}; use super::{fungible, Balance, Preservation::Expendable};
@@ -38,13 +39,15 @@ pub trait Pay {
type AssetKind; type AssetKind;
/// An identifier given to an individual payment. /// An identifier given to an individual payment.
type Id: FullCodec + MaxEncodedLen + TypeInfo + Clone + Eq + PartialEq + Debug + Copy; 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 /// 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). /// mechanism (likely an event, but possibly not on this chain).
fn pay( fn pay(
who: &Self::Beneficiary, who: &Self::Beneficiary,
asset_kind: Self::AssetKind, asset_kind: Self::AssetKind,
amount: Self::Balance, 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 /// 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 /// 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 /// `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> {
type Beneficiary = A::Type; type Beneficiary = A::Type;
type AssetKind = (); type AssetKind = ();
type Id = (); type Id = ();
type Error = DispatchError;
fn pay( fn pay(
who: &Self::Beneficiary, who: &Self::Beneficiary,
_: Self::AssetKind, _: Self::AssetKind,
amount: Self::Balance, amount: Self::Balance,
) -> Result<Self::Id, ()> { ) -> Result<Self::Id, Self::Error> {
<F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable).map_err(|_| ())?; <F as fungible::Mutate<_>>::transfer(&A::get(), who, amount, Expendable)?;
Ok(()) Ok(())
} }
fn check_payment(_: ()) -> PaymentStatus { fn check_payment(_: ()) -> PaymentStatus {