Macro sp_runtime::impl_tx_ext_default
source · macro_rules! impl_tx_ext_default { ($call:ty ; , $( $rest:tt )*) => { ... }; ($call:ty ; validate $( $rest:tt )*) => { ... }; ($call:ty ; prepare $( $rest:tt )*) => { ... }; ($call:ty ; weight $( $rest:tt )*) => { ... }; ($call:ty ;) => { ... }; }
Expand description
Helper macro to be used in a impl TransactionExtension
block to add default implementations of
weight
, validate
, prepare
or any combinations of the them.
The macro is to be used with 2 parameters, separated by “;”:
- the
Call
type; - the functions for which a default implementation should be generated, separated by “ “;
available options are
weight
,validate
andprepare
.
Example usage:
impl TransactionExtension<FirstCall> for EmptyExtension {
type Val = ();
type Pre = ();
impl_tx_ext_default!(FirstCall; weight validate prepare);
}
impl TransactionExtension<SecondCall> for SimpleExtension {
type Val = u32;
type Pre = ();
fn weight(&self, _: &SecondCall) -> Weight {
Weight::zero()
}
fn validate(
&self,
_origin: <T as Config>::RuntimeOrigin,
_call: &SecondCall,
_info: &DispatchInfoOf<SecondCall>,
_len: usize,
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
) -> ValidateResult<Self::Val, SecondCall> {
Ok((Default::default(), 42u32, origin))
}
impl_tx_ext_default!(SecondCall; prepare);
}