Replace 'Module' with 'Pallet' in construct_runtime macro (#8372)

* Use 'Pallet' struct in construct_runtime.

* Fix genesis and metadata macro.

* Fix 'Pallet' type alias.

* Replace 'Module' with 'Pallet' for all construct_runtime use cases.

* Replace more deprecated 'Module' struct.

* Bring back AllModules and AllPalletsWithSystem type, but deprecate them.

* Replace deprecated 'Module' struct from merge master.

* Minor fix.

* Fix UI tests.

* Revert UI override in derive_no_bound.

* Fix more deprecated 'Module' use from master branch.

* Fix more deprecated 'Module' use from master branch.
This commit is contained in:
Shaun Wang
2021-03-18 21:50:08 +13:00
committed by GitHub
parent 05f24931a9
commit 2e5522444a
157 changed files with 881 additions and 864 deletions
+7 -2
View File
@@ -1375,11 +1375,11 @@ macro_rules! decl_module {
impl<$trait_instance: $trait_name$(<I>, $instance: $instantiable)?> $module<$trait_instance $(, $instance)?>
where $( $other_where_bounds )*
{
/// Deposits an event using `frame_system::Module::deposit_event`.
/// Deposits an event using `frame_system::Pallet::deposit_event`.
$vis fn deposit_event(
event: impl Into<< $trait_instance as $trait_name $(<$instance>)? >::Event>
) {
<$system::Module<$trait_instance>>::deposit_event(event.into())
<$system::Pallet<$trait_instance>>::deposit_event(event.into())
}
}
};
@@ -1859,6 +1859,11 @@ macro_rules! decl_module {
>($crate::sp_std::marker::PhantomData<($trait_instance, $( $instance)?)>) where
$( $other_where_bounds )*;
/// Type alias to `Module`, to be used by `construct_runtime`.
#[allow(dead_code)]
pub type Pallet<$trait_instance $(, $instance $( = $module_default_instance)?)?>
= $mod_type<$trait_instance $(, $instance)?>;
$crate::decl_module! {
@impl_on_initialize
{ $system }
@@ -56,7 +56,7 @@ macro_rules! __impl_outer_config_types {
/// specific genesis configuration.
///
/// ```ignore
/// pub struct GenesisConfig for Runtime where AllModulesWithSystem = AllModulesWithSystem {
/// pub struct GenesisConfig for Runtime where AllPalletsWithSystem = AllPalletsWithSystem {
/// rust_module_one: Option<ModuleOneConfig>,
/// ...
/// }
@@ -65,7 +65,7 @@ macro_rules! __impl_outer_config_types {
macro_rules! impl_outer_config {
(
pub struct $main:ident for $concrete:ident where
AllModulesWithSystem = $all_modules_with_system:ident
AllPalletsWithSystem = $all_pallets_with_system:ident
{
$( $config:ident =>
$snake:ident $( $instance:ident )? $( <$generic:ident> )*, )*
@@ -103,7 +103,7 @@ macro_rules! impl_outer_config {
)*
$crate::BasicExternalities::execute_with_storage(storage, || {
<$all_modules_with_system as $crate::traits::OnGenesis>::on_genesis();
<$all_pallets_with_system as $crate::traits::OnGenesis>::on_genesis();
});
Ok(())
+6 -6
View File
@@ -58,7 +58,7 @@ pub use frame_metadata::{
///
/// struct Runtime;
/// frame_support::impl_runtime_metadata! {
/// for Runtime with modules where Extrinsic = UncheckedExtrinsic
/// for Runtime with pallets where Extrinsic = UncheckedExtrinsic
/// module0::Module as Module0 { index 0 } with,
/// module1::Module as Module1 { index 1 } with,
/// module2::Module as Module2 { index 2 } with Storage,
@@ -69,7 +69,7 @@ pub use frame_metadata::{
#[macro_export]
macro_rules! impl_runtime_metadata {
(
for $runtime:ident with modules where Extrinsic = $ext:ident
for $runtime:ident with pallets where Extrinsic = $ext:ident
$( $rest:tt )*
) => {
impl $runtime {
@@ -421,7 +421,7 @@ mod tests {
impl crate::traits::PalletInfo for TestRuntime {
fn index<P: 'static>() -> Option<usize> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<system::Module<TestRuntime>>() {
if type_id == sp_std::any::TypeId::of::<system::Pallet<TestRuntime>>() {
return Some(0)
}
if type_id == sp_std::any::TypeId::of::<EventModule>() {
@@ -435,7 +435,7 @@ mod tests {
}
fn name<P: 'static>() -> Option<&'static str> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<system::Module<TestRuntime>>() {
if type_id == sp_std::any::TypeId::of::<system::Pallet<TestRuntime>>() {
return Some("System")
}
if type_id == sp_std::any::TypeId::of::<EventModule>() {
@@ -492,8 +492,8 @@ mod tests {
}
impl_runtime_metadata!(
for TestRuntime with modules where Extrinsic = TestExtrinsic
system::Module as System { index 0 } with Event,
for TestRuntime with pallets where Extrinsic = TestExtrinsic
system::Pallet as System { index 0 } with Event,
event_module::Module as Module { index 1 } with Event Call,
event_module2::Module as Module2 { index 2 } with Event Storage Call,
);