diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 9981e5ad65b78..a26ca652d67be 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -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. /// @@ -339,6 +339,14 @@ pub trait WithPostDispatchInfo { /// ensure!(who == me, Error::::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::::InvalidParameters.with_pays_fee(Pays::No)); + /// ``` + fn with_pays_fee(self, pays_fee: Pays) -> DispatchErrorWithPostInfo; } impl WithPostDispatchInfo for T @@ -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(), + } + } } /// Implementation for unchecked extrinsic.