git.delta.rocks / unique-network / refs/commits / 8699eabfbbae

difftreelog

refactor simplify common construct_runtime

Daniel Shiposha2022-08-02parent: #a18bd7d.patch.diff
in: master

5 files changed

modifiedruntime/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,
modifiedruntime/common/src/construct_runtime/util.rsdiffbeforeafterboth
1#[macro_export]1#[macro_export]
2macro_rules! construct_runtime_impl {2macro_rules! construct_runtime_impl {
3 (3 (
4 pub enum $runtime:ident where4 select_runtime($select_runtime:ident);
5
6 pub enum Runtime where
5 $($where_ident:ident = $where_ty:ty),* $(,)?7 $($where_ident:ident = $where_ty:ty),* $(,)?
6 {8 {
7 $(9 $(
12 }14 }
13 ) => {15 ) => {
14 $crate::construct_runtime_helper! {16 $crate::construct_runtime_helper! {
15 runtime($runtime),17 select_runtime($select_runtime),
18 selected_pallets(),
19
16 where_clause($($where_ident = $where_ty),*),20 where_clause($($where_ident = $where_ty),*),
17 pallets(21 pallets(
18 $(22 $(
19 $(#[runtimes($($pallet_runtimes),+)])?23 $(#[runtimes($($pallet_runtimes),+)])?
20 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index24 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index
21 ),*,25 ),*,
22 ),26 )
23
24 opal_pallets(),
25 quartz_pallets(),
26 unique_pallets(),
27 }27 }
28 }28 }
29}29}
3030
31#[macro_export]31#[macro_export]
32macro_rules! construct_runtime_helper {32macro_rules! construct_runtime_helper {
33 (33 (
34 runtime($runtime:ident),34 select_runtime($select_runtime:ident),
35 selected_pallets($($selected_pallets:tt)*),
36
35 where_clause($($where_clause:tt)*),37 where_clause($($where_clause:tt)*),
36 pallets(38 pallets(
37 #[runtimes($($pallet_runtimes:ident),+)]39 #[runtimes($($pallet_runtimes:ident),+)]
38 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,40 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
3941
40 $($pallets_tl:tt)*42 $($pallets_tl:tt)*
41 ),43 )
42
43 opal_pallets($($opal_pallets:tt)*),
44 quartz_pallets($($quartz_pallets:tt)*),
45 unique_pallets($($unique_pallets:tt)*),
46 ) => {44 ) => {
47 $crate::add_runtime_specific_pallets! {45 $crate::add_runtime_specific_pallets! {
48 runtime($runtime),46 select_runtime($select_runtime),
47 runtimes($($pallet_runtimes),+,),
48 selected_pallets($($selected_pallets)*),
49
49 where_clause($($where_clause)*),50 where_clause($($where_clause)*),
50 pallets(51 pallets(
51 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,52 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
52 $($pallets_tl)*53 $($pallets_tl)*
53 ),54 )
54
55 runtimes($($pallet_runtimes),+,),
56
57 opal_pallets($($opal_pallets)*),
58 quartz_pallets($($quartz_pallets)*),
59 unique_pallets($($unique_pallets)*),
60 }55 }
61 };56 };
6257
63 (58 (
64 runtime($runtime:ident),59 select_runtime($select_runtime:ident),
60 selected_pallets($($selected_pallets:tt)*),
61
65 where_clause($($where_clause:tt)*),62 where_clause($($where_clause:tt)*),
66 pallets(63 pallets(
67 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,64 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
6865
69 $($pallets_tl:tt)*66 $($pallets_tl:tt)*
70 ),67 )
71
72 opal_pallets($($opal_pallets:tt)*),
73 quartz_pallets($($quartz_pallets:tt)*),
74 unique_pallets($($unique_pallets:tt)*),
75 ) => {68 ) => {
76 $crate::construct_runtime_helper! {69 $crate::construct_runtime_helper! {
77 runtime($runtime),70 select_runtime($select_runtime),
78 where_clause($($where_clause)*),
79 pallets($($pallets_tl)*),
80
81 opal_pallets(71 selected_pallets(
82 $($opal_pallets)*72 $($selected_pallets)*
83 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,73 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
84 ),74 ),
8575
86 quartz_pallets(76 where_clause($($where_clause)*),
87 $($quartz_pallets)*
88 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
89 ),
90
91 unique_pallets(77 pallets($($pallets_tl)*)
92 $($unique_pallets)*
93 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
94 ),
95 }78 }
96 };79 };
9780
98 (81 (
99 runtime($runtime:ident),82 select_runtime($select_runtime:ident),
100 where_clause($($where_clause:tt)*),83 selected_pallets($($selected_pallets:tt)*),
101 pallets(),
10284
103 opal_pallets($($opal_pallets:tt)*),85 where_clause($($where_clause:tt)*),
104 quartz_pallets($($quartz_pallets:tt)*),86 pallets()
105 unique_pallets($($unique_pallets:tt)*),
106 ) => {87 ) => {
107 #[cfg(feature = "opal-runtime")]
108 frame_support::construct_runtime! {88 frame_support::construct_runtime! {
109 pub enum $runtime where89 pub enum Runtime where
110 $($where_clause)*90 $($where_clause)*
111 {91 {
112 $($opal_pallets)*92 $($selected_pallets)*
113 }93 }
114 }94 }
115
116 #[cfg(feature = "quartz-runtime")]
117 frame_support::construct_runtime! {
118 pub enum $runtime where
119 $($where_clause)*
120 {
121 $($quartz_pallets)*
122 }
123 }
124
125 #[cfg(feature = "unique-runtime")]
126 frame_support::construct_runtime! {
127 pub enum $runtime where
128 $($where_clause)*
129 {
130 $($unique_pallets)*
131 }
132 }
133 };95 };
134}96}
13597
136#[macro_export]98#[macro_export]
137macro_rules! add_runtime_specific_pallets {99macro_rules! add_runtime_specific_pallets {
138 (100 (
101 select_runtime(opal),
139 runtime($runtime:ident),102 runtimes(opal, $($_runtime_tl:tt)*),
103 selected_pallets($($selected_pallets:tt)*),
104
140 where_clause($($where_clause:tt)*),105 where_clause($($where_clause:tt)*),
141 pallets(106 pallets(
142 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,107 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
143 $($pallets_tl:tt)*108 $($pallets_tl:tt)*
144 ),109 )
145
146 runtimes(
147 opal,
148
149 $($runtime_tl:tt)*
150 ),
151
152 opal_pallets($($opal_pallets:tt)*),
153 quartz_pallets($($quartz_pallets:tt)*),
154 unique_pallets($($unique_pallets:tt)*),
155 ) => {110 ) => {
156 $crate::add_runtime_specific_pallets! {111 $crate::construct_runtime_helper! {
157 runtime($runtime),112 select_runtime(opal),
158 where_clause($($where_clause)*),
159 pallets(
160 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
161 $($pallets_tl)*
162 ),
163
164 runtimes($($runtime_tl)*),
165
166 opal_pallets(113 selected_pallets(
167 $($opal_pallets)*114 $($selected_pallets)*
168 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,115 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
169 ),116 ),
117
170 quartz_pallets($($quartz_pallets)*),118 where_clause($($where_clause)*),
171 unique_pallets($($unique_pallets)*),119 pallets($($pallets_tl)*)
172 }120 }
173 };121 };
174122
175 (123 (
124 select_runtime(quartz),
176 runtime($runtime:ident),125 runtimes(quartz, $($_runtime_tl:tt)*),
126 selected_pallets($($selected_pallets:tt)*),
127
177 where_clause($($where_clause:tt)*),128 where_clause($($where_clause:tt)*),
178 pallets(129 pallets(
179 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,130 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
180 $($pallets_tl:tt)*131 $($pallets_tl:tt)*
181 ),132 )
182
183 runtimes(
184 quartz,
185
186 $($runtime_tl:tt)*
187 ),
188
189 opal_pallets($($opal_pallets:tt)*),
190 quartz_pallets($($quartz_pallets:tt)*),
191 unique_pallets($($unique_pallets:tt)*),
192 ) => {133 ) => {
193 $crate::add_runtime_specific_pallets! {134 $crate::construct_runtime_helper! {
135 select_runtime(quartz),
136 selected_pallets(
137 $($selected_pallets)*
138 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
139 ),
140
141 where_clause($($where_clause)*),
194 runtime($runtime),142 pallets($($pallets_tl)*)
143 }
144 };
145
146 (
147 select_runtime(unique),
148 runtimes(unique, $($_runtime_tl:tt)*),
149 selected_pallets($($selected_pallets:tt)*),
150
195 where_clause($($where_clause)*),151 where_clause($($where_clause:tt)*),
196 pallets(152 pallets(
197 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,153 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,
198 $($pallets_tl)*154 $($pallets_tl:tt)*
199 ),155 )
200156 ) => {
157 $crate::construct_runtime_helper! {
201 runtimes($($runtime_tl)*),158 select_runtime(unique),
202
203 opal_pallets($($opal_pallets)*),
204 quartz_pallets(159 selected_pallets(
205 $($quartz_pallets)*160 $($selected_pallets)*
206 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,161 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
207 ),162 ),
208 unique_pallets($($unique_pallets)*),163
209 }
210 };
211
212 (
213 runtime($runtime:ident),
214 where_clause($($where_clause:tt)*),164 where_clause($($where_clause)*),
215 pallets(165 pallets($($pallets_tl)*)
166 }
167 };
168
169 (
216 $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal,170 select_runtime($select_runtime:ident),
217 $($pallets_tl:tt)*
218 ),
219
220 runtimes(171 runtimes($_current_runtime:ident, $($runtime_tl:tt)*),
221 unique,
222
223 $($runtime_tl:tt)*
224 ),
225
226 opal_pallets($($opal_pallets:tt)*),172 selected_pallets($($selected_pallets:tt)*),
173
227 quartz_pallets($($quartz_pallets:tt)*),174 where_clause($($where_clause:tt)*),
228 unique_pallets($($unique_pallets:tt)*),175 pallets($($pallets:tt)*)
229 ) => {176 ) => {
230 $crate::add_runtime_specific_pallets! {177 $crate::add_runtime_specific_pallets! {
231 runtime($runtime),178 select_runtime($select_runtime),
232 where_clause($($where_clause)*),
233 pallets(
234 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
235 $($pallets_tl)*
236 ),
237
238 runtimes($($runtime_tl)*),179 runtimes($($runtime_tl)*),
239
240 opal_pallets($($opal_pallets)*),180 selected_pallets($($selected_pallets)*),
181
241 quartz_pallets($($quartz_pallets)*),182 where_clause($($where_clause)*),
242 unique_pallets(183 pallets($($pallets)*)
243 $($unique_pallets)*
244 $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index,
245 ),
246 }184 }
247 };185 };
248186
249 (187 (
250 runtime($runtime:ident),188 select_runtime($select_runtime:ident),
189 runtimes(),
190 selected_pallets($($selected_pallets:tt)*),
191
251 where_clause($($where_clause:tt)*),192 where_clause($($where_clause:tt)*),
252 pallets(193 pallets(
253 $_pallet_name:ident: $_pallet_mod:ident::{$($_pallet_parts:ty),*} = $_index:literal,194 $_pallet_name:ident: $_pallet_mod:ident::{$($_pallet_parts:ty),*} = $_index:literal,
254 $($pallets_tl:tt)*195 $($pallets_tl:tt)*
255 ),196 )
256
257 runtimes(),
258
259 opal_pallets($($opal_pallets:tt)*),
260 quartz_pallets($($quartz_pallets:tt)*),
261 unique_pallets($($unique_pallets:tt)*),
262 ) => {197 ) => {
263 $crate::construct_runtime_helper! {198 $crate::construct_runtime_helper! {
264 runtime($runtime),199 select_runtime($select_runtime),
265 where_clause($($where_clause)*),200 selected_pallets($($selected_pallets)*),
201
266 pallets($($pallets_tl)*),202 where_clause($($where_clause)*),
267
268 opal_pallets($($opal_pallets)*),203 pallets($($pallets_tl)*)
269 quartz_pallets($($quartz_pallets)*),
270 unique_pallets($($unique_pallets)*),
271 }204 }
272 };205 };
273}206}
modifiedruntime/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;
 
modifiedruntime/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;
 
modifiedruntime/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;