difftreelog
refactor simplify common construct_runtime
in: master
5 files changed
runtime/common/src/construct_runtime/mod.rsdiffbeforeafterboth223#[macro_export]3#[macro_export]4macro_rules! construct_runtime {4macro_rules! construct_runtime {5 () => {5 ($select_runtime:ident) => {6 $crate::construct_runtime_impl! {6 $crate::construct_runtime_impl! {7 select_runtime($select_runtime);87 pub enum Runtime where9 pub enum Runtime where8 Block = Block,10 Block = Block,runtime/common/src/construct_runtime/util.rsdiffbeforeafterboth--- a/runtime/common/src/construct_runtime/util.rs
+++ b/runtime/common/src/construct_runtime/util.rs
@@ -1,7 +1,9 @@
#[macro_export]
macro_rules! construct_runtime_impl {
(
- pub enum $runtime:ident where
+ select_runtime($select_runtime:ident);
+
+ pub enum Runtime where
$($where_ident:ident = $where_ty:ty),* $(,)?
{
$(
@@ -12,18 +14,16 @@
}
) => {
$crate::construct_runtime_helper! {
- runtime($runtime),
+ select_runtime($select_runtime),
+ selected_pallets(),
+
where_clause($($where_ident = $where_ty),*),
pallets(
$(
$(#[runtimes($($pallet_runtimes),+)])?
$pallet_name: $pallet_mod::{$($pallet_parts),*} = $index
),*,
- ),
-
- opal_pallets(),
- quartz_pallets(),
- unique_pallets(),
+ )
}
}
}
@@ -31,103 +31,65 @@
#[macro_export]
macro_rules! construct_runtime_helper {
(
- runtime($runtime:ident),
+ select_runtime($select_runtime:ident),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
#[runtimes($($pallet_runtimes:ident),+)]
$pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
$($pallets_tl:tt)*
- ),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ )
) => {
$crate::add_runtime_specific_pallets! {
- runtime($runtime),
+ select_runtime($select_runtime),
+ runtimes($($pallet_runtimes),+,),
+ selected_pallets($($selected_pallets)*),
+
where_clause($($where_clause)*),
pallets(
$pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
$($pallets_tl)*
- ),
-
- runtimes($($pallet_runtimes),+,),
-
- opal_pallets($($opal_pallets)*),
- quartz_pallets($($quartz_pallets)*),
- unique_pallets($($unique_pallets)*),
+ )
}
};
(
- runtime($runtime:ident),
+ select_runtime($select_runtime:ident),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
$pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
$($pallets_tl:tt)*
- ),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ )
) => {
$crate::construct_runtime_helper! {
- runtime($runtime),
- where_clause($($where_clause)*),
- pallets($($pallets_tl)*),
-
- opal_pallets(
- $($opal_pallets)*
+ select_runtime($select_runtime),
+ selected_pallets(
+ $($selected_pallets)*
$pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
),
- quartz_pallets(
- $($quartz_pallets)*
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- ),
-
- unique_pallets(
- $($unique_pallets)*
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- ),
+ where_clause($($where_clause)*),
+ pallets($($pallets_tl)*)
}
};
(
- runtime($runtime:ident),
+ select_runtime($select_runtime:ident),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
- pallets(),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ pallets()
) => {
- #[cfg(feature = "opal-runtime")]
frame_support::construct_runtime! {
- pub enum $runtime where
- $($where_clause)*
- {
- $($opal_pallets)*
- }
- }
-
- #[cfg(feature = "quartz-runtime")]
- frame_support::construct_runtime! {
- pub enum $runtime where
- $($where_clause)*
- {
- $($quartz_pallets)*
- }
- }
-
- #[cfg(feature = "unique-runtime")]
- frame_support::construct_runtime! {
- pub enum $runtime where
+ pub enum Runtime where
$($where_clause)*
{
- $($unique_pallets)*
+ $($selected_pallets)*
}
}
};
@@ -136,138 +98,109 @@
#[macro_export]
macro_rules! add_runtime_specific_pallets {
(
- runtime($runtime:ident),
+ select_runtime(opal),
+ runtimes(opal, $($_runtime_tl:tt)*),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
$pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
$($pallets_tl:tt)*
- ),
-
- runtimes(
- opal,
-
- $($runtime_tl:tt)*
- ),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ )
) => {
- $crate::add_runtime_specific_pallets! {
- runtime($runtime),
- where_clause($($where_clause)*),
- pallets(
+ $crate::construct_runtime_helper! {
+ select_runtime(opal),
+ selected_pallets(
+ $($selected_pallets)*
$pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- $($pallets_tl)*
),
- runtimes($($runtime_tl)*),
-
- opal_pallets(
- $($opal_pallets)*
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- ),
- quartz_pallets($($quartz_pallets)*),
- unique_pallets($($unique_pallets)*),
+ where_clause($($where_clause)*),
+ pallets($($pallets_tl)*)
}
};
(
- runtime($runtime:ident),
+ select_runtime(quartz),
+ runtimes(quartz, $($_runtime_tl:tt)*),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
$pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
$($pallets_tl:tt)*
- ),
-
- runtimes(
- quartz,
-
- $($runtime_tl:tt)*
- ),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ )
) => {
- $crate::add_runtime_specific_pallets! {
- runtime($runtime),
- where_clause($($where_clause)*),
- pallets(
+ $crate::construct_runtime_helper! {
+ select_runtime(quartz),
+ selected_pallets(
+ $($selected_pallets)*
$pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- $($pallets_tl)*
),
-
- runtimes($($runtime_tl)*),
- opal_pallets($($opal_pallets)*),
- quartz_pallets(
- $($quartz_pallets)*
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- ),
- unique_pallets($($unique_pallets)*),
+ where_clause($($where_clause)*),
+ pallets($($pallets_tl)*)
}
};
(
- runtime($runtime:ident),
+ select_runtime(unique),
+ runtimes(unique, $($_runtime_tl:tt)*),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
$pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
$($pallets_tl:tt)*
- ),
+ )
+ ) => {
+ $crate::construct_runtime_helper! {
+ select_runtime(unique),
+ selected_pallets(
+ $($selected_pallets)*
+ $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
+ ),
- runtimes(
- unique,
+ where_clause($($where_clause)*),
+ pallets($($pallets_tl)*)
+ }
+ };
- $($runtime_tl:tt)*
- ),
+ (
+ select_runtime($select_runtime:ident),
+ runtimes($_current_runtime:ident, $($runtime_tl:tt)*),
+ selected_pallets($($selected_pallets:tt)*),
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ where_clause($($where_clause:tt)*),
+ pallets($($pallets:tt)*)
) => {
$crate::add_runtime_specific_pallets! {
- runtime($runtime),
- where_clause($($where_clause)*),
- pallets(
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- $($pallets_tl)*
- ),
-
+ select_runtime($select_runtime),
runtimes($($runtime_tl)*),
+ selected_pallets($($selected_pallets)*),
- opal_pallets($($opal_pallets)*),
- quartz_pallets($($quartz_pallets)*),
- unique_pallets(
- $($unique_pallets)*
- $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
- ),
+ where_clause($($where_clause)*),
+ pallets($($pallets)*)
}
};
(
- runtime($runtime:ident),
+ select_runtime($select_runtime:ident),
+ runtimes(),
+ selected_pallets($($selected_pallets:tt)*),
+
where_clause($($where_clause:tt)*),
pallets(
$_pallet_name:ident: $_pallet_mod:ident::{$($_pallet_parts:ty),*} = $_index:literal,
$($pallets_tl:tt)*
- ),
-
- runtimes(),
-
- opal_pallets($($opal_pallets:tt)*),
- quartz_pallets($($quartz_pallets:tt)*),
- unique_pallets($($unique_pallets:tt)*),
+ )
) => {
$crate::construct_runtime_helper! {
- runtime($runtime),
- where_clause($($where_clause)*),
- pallets($($pallets_tl)*),
+ select_runtime($select_runtime),
+ selected_pallets($($selected_pallets)*),
- opal_pallets($($opal_pallets)*),
- quartz_pallets($($quartz_pallets)*),
- unique_pallets($($unique_pallets)*),
+ where_clause($($where_clause)*),
+ pallets($($pallets_tl)*)
}
};
}
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -1126,7 +1126,7 @@
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
}
-construct_runtime!();
+construct_runtime!(opal);
pub struct TransactionConverter;
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -33,7 +33,7 @@
#[cfg(feature = "scheduler")]
use sp_runtime::{
- traits::Member,
+ traits::{Applyable, Member},
generic::Era,
DispatchErrorWithPostInfo
};
@@ -1137,7 +1137,7 @@
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
}
-construct_runtime!();
+construct_runtime!(quartz);
pub struct TransactionConverter;
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -34,7 +34,7 @@
#[cfg(feature = "scheduler")]
use sp_runtime::{
- traits::Member,
+ traits::{Applyable, Member},
generic::Era,
DispatchErrorWithPostInfo
};
@@ -1139,7 +1139,7 @@
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
}
-construct_runtime!();
+construct_runtime!(unique);
pub struct TransactionConverter;