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
before · runtime/common/src/construct_runtime/mod.rs
1mod util;23#[macro_export]4macro_rules! construct_runtime {5    () => {6        $crate::construct_runtime_impl! {7            pub enum Runtime where8                Block = Block,9                NodeBlock = opaque::Block,10                UncheckedExtrinsic = UncheckedExtrinsic11            {12                ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,13                ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,1415                Aura: pallet_aura::{Pallet, Config<T>} = 22,16                AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,1718                Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,19                RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,20                Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,21                TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,22                Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,23                Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,24                System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,25                Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,26                // Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,27                // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,2829                // XCM helpers.30                XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,31                PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,32                CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,33                DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,3435                // Unique Pallets36                Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,37                Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,3839                #[runtimes(opal)]40                Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,4142                // free = 634344                Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,45                // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,46                Common: pallet_common::{Pallet, Storage, Event<T>} = 66,47                Fungible: pallet_fungible::{Pallet, Storage} = 67,4849                #[runtimes(opal)]50                Refungible: pallet_refungible::{Pallet, Storage} = 68,5152                Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,53                Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,5455                #[runtimes(opal)]56                RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,5758                #[runtimes(opal)]59                RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,6061                // Frontier62                EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,63                Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,6465                EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,66                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,67                EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,68                EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,69            }70        }71    }72}
after · runtime/common/src/construct_runtime/mod.rs
1mod util;23#[macro_export]4macro_rules! construct_runtime {5    ($select_runtime:ident) => {6        $crate::construct_runtime_impl! {7            select_runtime($select_runtime);89            pub enum Runtime where10                Block = Block,11                NodeBlock = opaque::Block,12                UncheckedExtrinsic = UncheckedExtrinsic13            {14                ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,15                ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,1617                Aura: pallet_aura::{Pallet, Config<T>} = 22,18                AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,1920                Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,21                RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,22                Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,23                TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33,24                Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,25                Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,26                System: frame_system::{Pallet, Call, Storage, Config, Event<T>} = 36,27                Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,28                // Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,29                // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,3031                // XCM helpers.32                XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,33                PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,34                CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,35                DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,3637                // Unique Pallets38                Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,39                Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,4041                #[runtimes(opal)]42                Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,4344                // free = 634546                Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,47                // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,48                Common: pallet_common::{Pallet, Storage, Event<T>} = 66,49                Fungible: pallet_fungible::{Pallet, Storage} = 67,5051                #[runtimes(opal)]52                Refungible: pallet_refungible::{Pallet, Storage} = 68,5354                Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,55                Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,5657                #[runtimes(opal)]58                RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,5960                #[runtimes(opal)]61                RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,6263                // Frontier64                EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,65                Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,6667                EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,68                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,69                EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,70                EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,71            }72        }73    }74}
modifiedruntime/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)*)
         }
     };
 }
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;