mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Add trait to get module and call names. (#4854)
* Add trait to get module and call names. Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -82,7 +82,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
// implementation changes and behavior does not, then leave spec_version as
|
// implementation changes and behavior does not, then leave spec_version as
|
||||||
// is and increment impl_version.
|
// is and increment impl_version.
|
||||||
spec_version: 215,
|
spec_version: 215,
|
||||||
impl_version: 0,
|
impl_version: 1,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1346,6 +1346,14 @@ macro_rules! decl_module {
|
|||||||
$call_type::__PhantomItem(_, _) => unreachable!("__PhantomItem should never be used."),
|
$call_type::__PhantomItem(_, _) => unreachable!("__PhantomItem should never be used."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_call_names() -> &'static [&'static str] {
|
||||||
|
&[
|
||||||
|
$(
|
||||||
|
stringify!($fn_name),
|
||||||
|
)*
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// manual implementation of clone/eq/partialeq because using derive erroneously requires
|
// manual implementation of clone/eq/partialeq because using derive erroneously requires
|
||||||
@@ -1518,6 +1526,24 @@ macro_rules! impl_outer_dispatch {
|
|||||||
}, )*
|
}, )*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_module_names() -> &'static [&'static str] {
|
||||||
|
&[$(
|
||||||
|
stringify!($camelcase),
|
||||||
|
)*]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_call_names(module: &str) -> &'static [&'static str] {
|
||||||
|
use $crate::dispatch::{Callable, GetCallName};
|
||||||
|
match module {
|
||||||
|
$(
|
||||||
|
stringify!($camelcase) =>
|
||||||
|
<<$camelcase as Callable<$runtime>>::Call
|
||||||
|
as GetCallName>::get_call_names(),
|
||||||
|
)*
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl $crate::dispatch::Dispatchable for $call_type {
|
impl $crate::dispatch::Dispatchable for $call_type {
|
||||||
type Origin = $origin;
|
type Origin = $origin;
|
||||||
@@ -2118,4 +2144,16 @@ mod tests {
|
|||||||
let expected = CallMetadata { function_name: "aux_3".into(), pallet_name: "Test".into() };
|
let expected = CallMetadata { function_name: "aux_3".into(), pallet_name: "Test".into() };
|
||||||
assert_eq!(metadata, expected);
|
assert_eq!(metadata, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_call_names() {
|
||||||
|
let call_names = Call::<TraitImpl>::get_call_names();
|
||||||
|
assert_eq!(["aux_0", "aux_1", "aux_2", "aux_3", "aux_4", "aux_5", "operational"], call_names);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_module_names() {
|
||||||
|
let module_names = OuterCall::get_module_names();
|
||||||
|
assert_eq!(["Test"], module_names);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -819,12 +819,18 @@ pub struct CallMetadata {
|
|||||||
|
|
||||||
/// Gets the function name of the Call.
|
/// Gets the function name of the Call.
|
||||||
pub trait GetCallName {
|
pub trait GetCallName {
|
||||||
|
/// Return all function names.
|
||||||
|
fn get_call_names() -> &'static [&'static str];
|
||||||
/// Return the function name of the Call.
|
/// Return the function name of the Call.
|
||||||
fn get_call_name(&self) -> &'static str;
|
fn get_call_name(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the metadata for the Call - function name and pallet name.
|
/// Gets the metadata for the Call - function name and pallet name.
|
||||||
pub trait GetCallMetadata {
|
pub trait GetCallMetadata {
|
||||||
|
/// Return all module names.
|
||||||
|
fn get_module_names() -> &'static [&'static str];
|
||||||
|
/// Return all function names for the given `module`.
|
||||||
|
fn get_call_names(module: &str) -> &'static [&'static str];
|
||||||
/// Return a [`CallMetadata`], containing function and pallet name of the Call.
|
/// Return a [`CallMetadata`], containing function and pallet name of the Call.
|
||||||
fn get_call_metadata(&self) -> CallMetadata;
|
fn get_call_metadata(&self) -> CallMetadata;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user