GetCallIndex trait (#13558)

* GetCallIndex trait

* final impl

* ".git/.scripts/commands/fmt/fmt.sh"

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* One more test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Doc

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Kasper Ziemianek
2023-03-22 13:13:31 +01:00
committed by GitHub
parent c2f32c9cbd
commit be734195c3
6 changed files with 56 additions and 8 deletions
@@ -984,7 +984,8 @@ pub fn compact(_: TokenStream, _: TokenStream) -> TokenStream {
///
/// The macro creates an enum `Call` with one variant per dispatchable. This enum implements:
/// [`Clone`], [`Eq`], [`PartialEq`], [`Debug`] (with stripped implementation in `not("std")`),
/// `Encode`, `Decode`, `GetDispatchInfo`, `GetCallName`, and `UnfilteredDispatchable`.
/// `Encode`, `Decode`, `GetDispatchInfo`, `GetCallName`, `GetCallIndex` and
/// `UnfilteredDispatchable`.
///
/// The macro implements the `Callable` trait on `Pallet` and a function `call_functions`
/// which returns the dispatchable metadata.
@@ -324,6 +324,21 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
}
}
impl<#type_impl_gen> #frame_support::dispatch::GetCallIndex for #call_ident<#type_use_gen>
#where_clause
{
fn get_call_index(&self) -> u8 {
match *self {
#( Self::#fn_name { .. } => #call_index, )*
Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."),
}
}
fn get_call_indices() -> &'static [u8] {
&[ #( #call_index, )* ]
}
}
impl<#type_impl_gen> #frame_support::traits::UnfilteredDispatchable
for #call_ident<#type_use_gen>
#where_clause