mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Rename ModuleToIndex to PalletRuntimeSetup (#7148)
* Rename `ModuleToIndex` to `PalletRuntimeSetup` Besides the renaming it also adds support getting the name of a pallet as configured in the runtime. * Rename it to `PalletInfo` * Remove accidentally added files
This commit is contained in:
@@ -140,8 +140,8 @@ macro_rules! decl_error {
|
||||
for $crate::sp_runtime::DispatchError
|
||||
{
|
||||
fn from(err: $error<$generic $(, $inst_generic)?>) -> Self {
|
||||
let index = <$generic::ModuleToIndex as $crate::traits::ModuleToIndex>
|
||||
::module_to_index::<$module<$generic $(, $inst_generic)?>>()
|
||||
let index = <$generic::PalletInfo as $crate::traits::PalletInfo>
|
||||
::index::<$module<$generic $(, $inst_generic)?>>()
|
||||
.expect("Every active module has an index in the runtime; qed") as u8;
|
||||
|
||||
$crate::sp_runtime::DispatchError::Module {
|
||||
|
||||
@@ -297,7 +297,7 @@ mod tests {
|
||||
type AccountId: From<u32> + Encode;
|
||||
type BlockNumber: From<u32> + Encode;
|
||||
type SomeValue: Get<u32>;
|
||||
type ModuleToIndex: crate::traits::ModuleToIndex;
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type Call;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ mod tests {
|
||||
type AccountId = u32;
|
||||
type BlockNumber = u32;
|
||||
type SomeValue = SystemValue;
|
||||
type ModuleToIndex = ();
|
||||
type PalletInfo = ();
|
||||
type Call = Call;
|
||||
}
|
||||
|
||||
|
||||
@@ -1313,8 +1313,6 @@ impl<T: Clone + Ord> ChangeMembers<T> for () {
|
||||
fn set_prime(_: Option<T>) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Trait for type that can handle the initialization of account IDs at genesis.
|
||||
pub trait InitializeMembers<AccountId> {
|
||||
/// Initialize the members to the given `members`.
|
||||
@@ -1380,16 +1378,20 @@ pub trait ValidatorRegistration<ValidatorId> {
|
||||
fn is_registered(id: &ValidatorId) -> bool;
|
||||
}
|
||||
|
||||
/// Something that can convert a given module into the index of the module in the runtime.
|
||||
/// Provides information about the pallet setup in the runtime.
|
||||
///
|
||||
/// The index of a module is determined by the position it appears in `construct_runtime!`.
|
||||
pub trait ModuleToIndex {
|
||||
/// Convert the given module `M` into an index.
|
||||
fn module_to_index<M: 'static>() -> Option<usize>;
|
||||
/// An implementor should be able to provide information about each pallet that
|
||||
/// is configured in `construct_runtime!`.
|
||||
pub trait PalletInfo {
|
||||
/// Convert the given pallet `P` into its index as configured in the runtime.
|
||||
fn index<P: 'static>() -> Option<usize>;
|
||||
/// Convert the given pallet `P` into its name as configured in the runtime.
|
||||
fn name<P: 'static>() -> Option<&'static str>;
|
||||
}
|
||||
|
||||
impl ModuleToIndex for () {
|
||||
fn module_to_index<M: 'static>() -> Option<usize> { Some(0) }
|
||||
impl PalletInfo for () {
|
||||
fn index<P: 'static>() -> Option<usize> { Some(0) }
|
||||
fn name<P: 'static>() -> Option<&'static str> { Some("test") }
|
||||
}
|
||||
|
||||
/// The function and pallet name of the Call.
|
||||
|
||||
Reference in New Issue
Block a user