difftreelog
refactor simplify common construct_runtime
in: master
5 files changed
runtime/common/src/construct_runtime/mod.rsdiffbeforeafterboth--- a/runtime/common/src/construct_runtime/mod.rs
+++ b/runtime/common/src/construct_runtime/mod.rs
@@ -2,8 +2,10 @@
#[macro_export]
macro_rules! construct_runtime {
- () => {
+ ($select_runtime:ident) => {
$crate::construct_runtime_impl! {
+ select_runtime($select_runtime);
+
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
runtime/common/src/construct_runtime/util.rsdiffbeforeafterboth1#[macro_export]2macro_rules! construct_runtime_impl {3 (4 pub enum $runtime:ident where5 $($where_ident:ident = $where_ty:ty),* $(,)?6 {7 $(8 $(#[runtimes($($pallet_runtimes:ident),+ $(,)?)])?9 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal10 ),*11 $(,)?12 }13 ) => {14 $crate::construct_runtime_helper! {15 runtime($runtime),16 where_clause($($where_ident = $where_ty),*),17 pallets(18 $(19 $(#[runtimes($($pallet_runtimes),+)])?20 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index21 ),*,22 ),2324 opal_pallets(),25 quartz_pallets(),26 unique_pallets(),27 }28 }29}3031#[macro_export]32macro_rules! construct_runtime_helper {33 (34 runtime($runtime:ident),35 where_clause($($where_clause:tt)*),36 pallets(37 #[runtimes($($pallet_runtimes:ident),+)]38 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,3940 $($pallets_tl:tt)*41 ),4243 opal_pallets($($opal_pallets:tt)*),44 quartz_pallets($($quartz_pallets:tt)*),45 unique_pallets($($unique_pallets:tt)*),46 ) => {47 $crate::add_runtime_specific_pallets! {48 runtime($runtime),49 where_clause($($where_clause)*),50 pallets(51 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,52 $($pallets_tl)*53 ),5455 runtimes($($pallet_runtimes),+,),5657 opal_pallets($($opal_pallets)*),58 quartz_pallets($($quartz_pallets)*),59 unique_pallets($($unique_pallets)*),60 }61 };6263 (64 runtime($runtime:ident),65 where_clause($($where_clause:tt)*),66 pallets(67 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,6869 $($pallets_tl:tt)*70 ),7172 opal_pallets($($opal_pallets:tt)*),73 quartz_pallets($($quartz_pallets:tt)*),74 unique_pallets($($unique_pallets:tt)*),75 ) => {76 $crate::construct_runtime_helper! {77 runtime($runtime),78 where_clause($($where_clause)*),79 pallets($($pallets_tl)*),8081 opal_pallets(82 $($opal_pallets)*83 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,84 ),8586 quartz_pallets(87 $($quartz_pallets)*88 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,89 ),9091 unique_pallets(92 $($unique_pallets)*93 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,94 ),95 }96 };9798 (99 runtime($runtime:ident),100 where_clause($($where_clause:tt)*),101 pallets(),102103 opal_pallets($($opal_pallets:tt)*),104 quartz_pallets($($quartz_pallets:tt)*),105 unique_pallets($($unique_pallets:tt)*),106 ) => {107 #[cfg(feature = "opal-runtime")]108 frame_support::construct_runtime! {109 pub enum $runtime where110 $($where_clause)*111 {112 $($opal_pallets)*113 }114 }115116 #[cfg(feature = "quartz-runtime")]117 frame_support::construct_runtime! {118 pub enum $runtime where119 $($where_clause)*120 {121 $($quartz_pallets)*122 }123 }124125 #[cfg(feature = "unique-runtime")]126 frame_support::construct_runtime! {127 pub enum $runtime where128 $($where_clause)*129 {130 $($unique_pallets)*131 }132 }133 };134}135136#[macro_export]137macro_rules! add_runtime_specific_pallets {138 (139 runtime($runtime:ident),140 where_clause($($where_clause:tt)*),141 pallets(142 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,143 $($pallets_tl:tt)*144 ),145146 runtimes(147 opal,148149 $($runtime_tl:tt)*150 ),151152 opal_pallets($($opal_pallets:tt)*),153 quartz_pallets($($quartz_pallets:tt)*),154 unique_pallets($($unique_pallets:tt)*),155 ) => {156 $crate::add_runtime_specific_pallets! {157 runtime($runtime),158 where_clause($($where_clause)*),159 pallets(160 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,161 $($pallets_tl)*162 ),163164 runtimes($($runtime_tl)*),165166 opal_pallets(167 $($opal_pallets)*168 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,169 ),170 quartz_pallets($($quartz_pallets)*),171 unique_pallets($($unique_pallets)*),172 }173 };174175 (176 runtime($runtime:ident),177 where_clause($($where_clause:tt)*),178 pallets(179 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,180 $($pallets_tl:tt)*181 ),182183 runtimes(184 quartz,185186 $($runtime_tl:tt)*187 ),188189 opal_pallets($($opal_pallets:tt)*),190 quartz_pallets($($quartz_pallets:tt)*),191 unique_pallets($($unique_pallets:tt)*),192 ) => {193 $crate::add_runtime_specific_pallets! {194 runtime($runtime),195 where_clause($($where_clause)*),196 pallets(197 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,198 $($pallets_tl)*199 ),200201 runtimes($($runtime_tl)*),202203 opal_pallets($($opal_pallets)*),204 quartz_pallets(205 $($quartz_pallets)*206 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,207 ),208 unique_pallets($($unique_pallets)*),209 }210 };211212 (213 runtime($runtime:ident),214 where_clause($($where_clause:tt)*),215 pallets(216 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,217 $($pallets_tl:tt)*218 ),219220 runtimes(221 unique,222223 $($runtime_tl:tt)*224 ),225226 opal_pallets($($opal_pallets:tt)*),227 quartz_pallets($($quartz_pallets:tt)*),228 unique_pallets($($unique_pallets:tt)*),229 ) => {230 $crate::add_runtime_specific_pallets! {231 runtime($runtime),232 where_clause($($where_clause)*),233 pallets(234 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,235 $($pallets_tl)*236 ),237238 runtimes($($runtime_tl)*),239240 opal_pallets($($opal_pallets)*),241 quartz_pallets($($quartz_pallets)*),242 unique_pallets(243 $($unique_pallets)*244 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,245 ),246 }247 };248249 (250 runtime($runtime:ident),251 where_clause($($where_clause:tt)*),252 pallets(253 $_pallet_name:ident: $_pallet_mod:ident::{$($_pallet_parts:ty),*} = $_index:literal,254 $($pallets_tl:tt)*255 ),256257 runtimes(),258259 opal_pallets($($opal_pallets:tt)*),260 quartz_pallets($($quartz_pallets:tt)*),261 unique_pallets($($unique_pallets:tt)*),262 ) => {263 $crate::construct_runtime_helper! {264 runtime($runtime),265 where_clause($($where_clause)*),266 pallets($($pallets_tl)*),267268 opal_pallets($($opal_pallets)*),269 quartz_pallets($($quartz_pallets)*),270 unique_pallets($($unique_pallets)*),271 }272 };273}1#[macro_export]2macro_rules! construct_runtime_impl {3 (4 select_runtime($select_runtime:ident);56 pub enum Runtime where7 $($where_ident:ident = $where_ty:ty),* $(,)?8 {9 $(10 $(#[runtimes($($pallet_runtimes:ident),+ $(,)?)])?11 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal12 ),*13 $(,)?14 }15 ) => {16 $crate::construct_runtime_helper! {17 select_runtime($select_runtime),18 selected_pallets(),1920 where_clause($($where_ident = $where_ty),*),21 pallets(22 $(23 $(#[runtimes($($pallet_runtimes),+)])?24 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index25 ),*,26 )27 }28 }29}3031#[macro_export]32macro_rules! construct_runtime_helper {33 (34 select_runtime($select_runtime:ident),35 selected_pallets($($selected_pallets:tt)*),3637 where_clause($($where_clause:tt)*),38 pallets(39 #[runtimes($($pallet_runtimes:ident),+)]40 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,4142 $($pallets_tl:tt)*43 )44 ) => {45 $crate::add_runtime_specific_pallets! {46 select_runtime($select_runtime),47 runtimes($($pallet_runtimes),+,),48 selected_pallets($($selected_pallets)*),4950 where_clause($($where_clause)*),51 pallets(52 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,53 $($pallets_tl)*54 )55 }56 };5758 (59 select_runtime($select_runtime:ident),60 selected_pallets($($selected_pallets:tt)*),6162 where_clause($($where_clause:tt)*),63 pallets(64 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,6566 $($pallets_tl:tt)*67 )68 ) => {69 $crate::construct_runtime_helper! {70 select_runtime($select_runtime),71 selected_pallets(72 $($selected_pallets)*73 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,74 ),7576 where_clause($($where_clause)*),77 pallets($($pallets_tl)*)78 }79 };8081 (82 select_runtime($select_runtime:ident),83 selected_pallets($($selected_pallets:tt)*),8485 where_clause($($where_clause:tt)*),86 pallets()87 ) => {88 frame_support::construct_runtime! {89 pub enum Runtime where90 $($where_clause)*91 {92 $($selected_pallets)*93 }94 }95 };96}9798#[macro_export]99macro_rules! add_runtime_specific_pallets {100 (101 select_runtime(opal),102 runtimes(opal, $($_runtime_tl:tt)*),103 selected_pallets($($selected_pallets:tt)*),104105 where_clause($($where_clause:tt)*),106 pallets(107 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,108 $($pallets_tl:tt)*109 )110 ) => {111 $crate::construct_runtime_helper! {112 select_runtime(opal),113 selected_pallets(114 $($selected_pallets)*115 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,116 ),117118 where_clause($($where_clause)*),119 pallets($($pallets_tl)*)120 }121 };122123 (124 select_runtime(quartz),125 runtimes(quartz, $($_runtime_tl:tt)*),126 selected_pallets($($selected_pallets:tt)*),127128 where_clause($($where_clause:tt)*),129 pallets(130 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,131 $($pallets_tl:tt)*132 )133 ) => {134 $crate::construct_runtime_helper! {135 select_runtime(quartz),136 selected_pallets(137 $($selected_pallets)*138 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,139 ),140141 where_clause($($where_clause)*),142 pallets($($pallets_tl)*)143 }144 };145146 (147 select_runtime(unique),148 runtimes(unique, $($_runtime_tl:tt)*),149 selected_pallets($($selected_pallets:tt)*),150151 where_clause($($where_clause:tt)*),152 pallets(153 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,154 $($pallets_tl:tt)*155 )156 ) => {157 $crate::construct_runtime_helper! {158 select_runtime(unique),159 selected_pallets(160 $($selected_pallets)*161 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,162 ),163164 where_clause($($where_clause)*),165 pallets($($pallets_tl)*)166 }167 };168169 (170 select_runtime($select_runtime:ident),171 runtimes($_current_runtime:ident, $($runtime_tl:tt)*),172 selected_pallets($($selected_pallets:tt)*),173174 where_clause($($where_clause:tt)*),175 pallets($($pallets:tt)*)176 ) => {177 $crate::add_runtime_specific_pallets! {178 select_runtime($select_runtime),179 runtimes($($runtime_tl)*),180 selected_pallets($($selected_pallets)*),181182 where_clause($($where_clause)*),183 pallets($($pallets)*)184 }185 };186187 (188 select_runtime($select_runtime:ident),189 runtimes(),190 selected_pallets($($selected_pallets:tt)*),191192 where_clause($($where_clause:tt)*),193 pallets(194 $_pallet_name:ident: $_pallet_mod:ident::{$($_pallet_parts:ty),*} = $_index:literal,195 $($pallets_tl:tt)*196 )197 ) => {198 $crate::construct_runtime_helper! {199 select_runtime($select_runtime),200 selected_pallets($($selected_pallets)*),201202 where_clause($($where_clause)*),203 pallets($($pallets_tl)*)204 }205 };206}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;