Attribute Macro frame_support::pallet_macros::feeless_if

source ·
#[feeless_if]
Expand description

Allows defining logic to make an extrinsic call feeless.

Each dispatchable may be annotated with the #[pallet::feeless_if($closure)] attribute, which explicitly defines the condition for the dispatchable to be feeless.

The arguments for the closure must be the referenced arguments of the dispatchable function.

The closure must return bool.

§Example

#[frame_support::pallet(dev_mode)]
mod pallet {
	#[pallet::pallet]
	pub struct Pallet<T>(_);

	#[pallet::call]
	impl<T: Config> Pallet<T> {
		#[pallet::call_index(0)]
		/// Marks this call as feeless if `foo` is zero.
		#[pallet::feeless_if(|_origin: &OriginFor<T>, foo: &u32| -> bool {
			*foo == 0
		})]
		pub fn something(
			_: OriginFor<T>,
			foo: u32,
		) -> DispatchResult {
			unimplemented!()
		}
	}
}

Please note that this only works for signed dispatchables and requires a signed extension such as pallet_skip_feeless_payment::SkipCheckIfFeeless to wrap the existing payment extension. Else, this is completely ignored and the dispatchable is still charged.

§Macro expansion

The macro implements the pallet_skip_feeless_payment::CheckIfFeeless trait on the dispatchable and calls the corresponding closure in the implementation.


Documentation for this macro can be found at frame_support::pallet_macros::feeless_if.