Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
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
16 changes: 15 additions & 1 deletion frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl sp_runtime::traits::Printable for PostDispatchInfo {
}

/// Allows easy conversion from `DispatchError` to `DispatchErrorWithPostInfo` for dispatchables
/// that want to return a custom a posterior weight on error.
/// that want to return a custom posterior weight or fee payment decision on error.
pub trait WithPostDispatchInfo {
/// Call this on your modules custom errors type in order to return a custom weight on error.
///
Expand All @@ -339,6 +339,14 @@ pub trait WithPostDispatchInfo {
/// ensure!(who == me, Error::<T>::NotMe.with_weight(200_000));
/// ```
fn with_weight(self, actual_weight: Weight) -> DispatchErrorWithPostInfo;
/// Call this on your modules custom errors type in order to decide fee payment on error.
///
/// # Example
///
/// ```ignore
/// ensure!(validate(params), Error::<T>::InvalidParameters.with_pays_fee(Pays::No));
/// ```
fn with_pays_fee(self, pays_fee: Pays) -> DispatchErrorWithPostInfo;
}

impl<T> WithPostDispatchInfo for T
Expand All @@ -354,6 +362,12 @@ where
error: self.into(),
}
}
fn with_pays_fee(self, pays_fee: Pays) -> DispatchErrorWithPostInfo {
DispatchErrorWithPostInfo {
post_info: PostDispatchInfo { actual_weight: None, pays_fee },
error: self.into(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like to me that we really should add a new function called with_post_info, so that callers can freely decide whether or not they want to use the default or modify any of the fields.

These methods should also exist in PostDispatchInfo rather than here as well, as it's not clear that the function actually returns a DispatchErrorWtihPostInfo after calling it.

}

/// Implementation for unchecked extrinsic.
Expand Down