git.delta.rocks / unique-network / refs/commits / 776f7511b7e5

difftreelog

refactor simplify construct_runtime

Daniel Shiposha2023-01-09parent: #fe83568.patch.diff
in: master

10 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8942,6 +8942,7 @@
  "pallet-structure",
  "pallet-sudo",
  "pallet-template-transaction-payment",
+ "pallet-test-utils",
  "pallet-timestamp",
  "pallet-transaction-payment",
  "pallet-transaction-payment-rpc-runtime-api",
@@ -13174,6 +13175,7 @@
  "pallet-structure",
  "pallet-sudo",
  "pallet-template-transaction-payment",
+ "pallet-test-utils",
  "pallet-timestamp",
  "pallet-transaction-payment",
  "pallet-transaction-payment-rpc-runtime-api",
addedruntime/common/construct_runtime.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/construct_runtime.rs
@@ -0,0 +1,113 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+#[macro_export]
+macro_rules! construct_runtime {
+    () => {
+            frame_support::construct_runtime! {
+
+            pub enum Runtime where
+                Block = Block,
+                NodeBlock = opaque::Block,
+                UncheckedExtrinsic = UncheckedExtrinsic
+            {
+                System: frame_system = 0,
+
+                ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,
+                ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
+
+                #[cfg(feature = "collator-selection")]
+                Authorship: pallet_authorship::{Pallet, Call, Storage} = 22,
+
+                #[cfg(feature = "collator-selection")]
+                CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>} = 23,
+
+                #[cfg(feature = "collator-selection")]
+                Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 24,
+
+                Aura: pallet_aura::{Pallet, Config<T>} = 25,
+                AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 26,
+
+                Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
+                RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,
+                Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,
+                TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 33,
+                Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,
+                Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,
+                Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,
+
+                XTokens: orml_xtokens = 38,
+                Tokens: orml_tokens = 39,
+                // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,
+
+                #[cfg(feature = "collator-selection")]
+                Identity: pallet_identity::{Pallet, Call, Storage, Event<T>} = 40,
+
+                // XCM helpers.
+                XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,
+                PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,
+                CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,
+                DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,
+
+                // Unique Pallets
+                Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
+                Unique: pallet_unique::{Pallet, Call, Storage} = 61,
+
+                // #[cfg(feature = "scheduler")]
+                // Scheduler: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 62,
+
+                Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>} = 63,
+
+                Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,
+                // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,
+                Common: pallet_common::{Pallet, Storage, Event<T>} = 66,
+                Fungible: pallet_fungible::{Pallet, Storage} = 67,
+
+                #[cfg(feature = "refungible")]
+                Refungible: pallet_refungible::{Pallet, Storage} = 68,
+
+                Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
+                Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
+
+                #[cfg(feature = "rmrk")]
+                RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
+
+                #[cfg(feature = "rmrk")]
+                RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,
+
+                #[cfg(feature = "app-promotion")]
+                AppPromotion: pallet_app_promotion::{Pallet, Call, Storage, Event<T>} = 73,
+
+                #[cfg(feature = "foreign-assets")]
+                ForeignAssets: pallet_foreign_assets::{Pallet, Call, Storage, Event<T>} = 80,
+
+                // Frontier
+                EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
+                Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,
+
+                EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,
+                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage, Event<T>} = 151,
+                EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,
+                EvmMigration: pallet_evm_migration::{Pallet, Call, Storage, Event<T>} = 153,
+
+                Maintenance: pallet_maintenance::{Pallet, Call, Storage, Event<T>} = 154,
+
+                #[cfg(feature = "pallet-test-utils")]
+                TestUtils: pallet_test_utils = 255,
+            }
+        }
+    }
+}
deletedruntime/common/construct_runtime/mod.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime/mod.rs
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-mod util;
-
-#[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,
-                UncheckedExtrinsic = UncheckedExtrinsic
-            {
-                System: frame_system = 0,
-
-                ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,
-                ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
-
-                #[runtimes(quartz)]
-                Authorship: pallet_authorship::{Pallet, Call, Storage} = 22,
-
-                #[runtimes(quartz)]
-                CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>} = 23,
-
-                #[runtimes(quartz)]
-                Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 24,
-
-                Aura: pallet_aura::{Pallet, Config<T>} = 25,
-                AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 26,
-
-                Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
-                RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,
-                Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,
-                TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 33,
-                Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,
-                Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,
-                Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,
-
-                XTokens: orml_xtokens = 38,
-                Tokens: orml_tokens = 39,
-                // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,
-
-                #[runtimes(quartz)]
-                Identity: pallet_identity::{Pallet, Call, Storage, Event<T>} = 40,
-
-                // XCM helpers.
-                XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,
-                PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,
-                CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,
-                DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,
-
-                // Unique Pallets
-                Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
-                Unique: pallet_unique::{Pallet, Call, Storage} = 61,
-
-                // #[runtimes(opal)]
-                // Scheduler: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 62,
-
-                Configuration: pallet_configuration::{Pallet, Call, Storage, Event<T>} = 63,
-
-                Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,
-                // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,
-                Common: pallet_common::{Pallet, Storage, Event<T>} = 66,
-                Fungible: pallet_fungible::{Pallet, Storage} = 67,
-
-                #[runtimes(opal, quartz)]
-                Refungible: pallet_refungible::{Pallet, Storage} = 68,
-
-                Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
-                Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
-
-                #[runtimes(opal)]
-                RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
-
-                #[runtimes(opal)]
-                RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,
-
-                #[runtimes(opal, quartz)]
-                AppPromotion: pallet_app_promotion::{Pallet, Call, Storage, Event<T>} = 73,
-
-                #[runtimes(opal, quartz, unique)]
-                ForeignAssets: pallet_foreign_assets::{Pallet, Call, Storage, Event<T>} = 80,
-
-                // Frontier
-                EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
-                Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,
-
-                EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,
-                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage, Event<T>} = 151,
-                EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,
-                EvmMigration: pallet_evm_migration::{Pallet, Call, Storage, Event<T>} = 153,
-
-                Maintenance: pallet_maintenance::{Pallet, Call, Storage, Event<T>} = 154,
-
-                #[runtimes(opal)]
-                TestUtils: pallet_test_utils = 255,
-            }
-        }
-    }
-}
deletedruntime/common/construct_runtime/util.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime/util.rs
+++ /dev/null
@@ -1,222 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-#[macro_export]
-macro_rules! construct_runtime_impl {
-    (
-        select_runtime($select_runtime:ident);
-
-        pub enum Runtime where
-            $($where_ident:ident = $where_ty:ty),* $(,)?
-        {
-            $(
-                $(#[runtimes($($pallet_runtimes:ident),+ $(,)?)])?
-                $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal
-            ),*
-            $(,)?
-        }
-    ) => {
-        $crate::construct_runtime_helper! {
-            select_runtime($select_runtime),
-            selected_pallets(),
-
-            where_clause($($where_ident = $where_ty),*),
-            pallets(
-                $(
-                    $(#[runtimes($($pallet_runtimes),+)])?
-                    $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index
-                ),*,
-            )
-        }
-    }
-}
-
-#[macro_export]
-macro_rules! construct_runtime_helper {
-    (
-        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)*
-        )
-    ) => {
-        $crate::add_runtime_specific_pallets! {
-            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)*
-            )
-        }
-    };
-
-    (
-        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)*
-        )
-    ) => {
-        $crate::construct_runtime_helper! {
-            select_runtime($select_runtime),
-            selected_pallets(
-                $($selected_pallets)*
-                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,
-            ),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets_tl)*)
-        }
-    };
-
-    (
-        select_runtime($select_runtime:ident),
-        selected_pallets($($selected_pallets:tt)*),
-
-        where_clause($($where_clause:tt)*),
-        pallets()
-    ) => {
-        frame_support::construct_runtime! {
-            pub enum Runtime where
-                $($where_clause)*
-            {
-                $($selected_pallets)*
-            }
-        }
-    };
-}
-
-#[macro_export]
-macro_rules! add_runtime_specific_pallets {
-    (
-        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)*
-        )
-    ) => {
-        $crate::construct_runtime_helper! {
-            select_runtime(opal),
-            selected_pallets(
-                $($selected_pallets)*
-                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,
-            ),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets_tl)*)
-        }
-    };
-
-    (
-        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)*
-        )
-    ) => {
-        $crate::construct_runtime_helper! {
-            select_runtime(quartz),
-            selected_pallets(
-                $($selected_pallets)*
-                $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,
-            ),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets_tl)*)
-        }
-    };
-
-    (
-        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,
-            ),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets_tl)*)
-        }
-    };
-
-    (
-        select_runtime($select_runtime:ident),
-        runtimes($_current_runtime:ident, $($runtime_tl:tt)*),
-        selected_pallets($($selected_pallets:tt)*),
-
-        where_clause($($where_clause:tt)*),
-        pallets($($pallets:tt)*)
-    ) => {
-        $crate::add_runtime_specific_pallets! {
-            select_runtime($select_runtime),
-            runtimes($($runtime_tl)*),
-            selected_pallets($($selected_pallets)*),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets)*)
-        }
-    };
-
-    (
-        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)*
-        )
-    ) => {
-        $crate::construct_runtime_helper! {
-            select_runtime($select_runtime),
-            selected_pallets($($selected_pallets)*),
-
-            where_clause($($where_clause)*),
-            pallets($($pallets_tl)*)
-        }
-    };
-}
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -98,7 +98,7 @@
     'pallet-base-fee/try-runtime',
     'pallet-unique-scheduler-v2/try-runtime',
     'pallet-maintenance/try-runtime',
-    'pallet-test-utils?/try-runtime',
+    'pallet-test-utils/try-runtime',
     'fp-self-contained/try-runtime',
 ]
 std = [
@@ -186,7 +186,7 @@
     "pallet-foreign-assets/std",
 
     'pallet-maintenance/std',
-    'pallet-test-utils?/std',
+    'pallet-test-utils/std',
 ]
 limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing']
 opal-runtime = [
@@ -204,6 +204,7 @@
 foreign-assets = []
 app-promotion = []
 collator-selection = []
+pallet-test-utils = []
 
 ################################################################################
 # Substrate Dependencies
@@ -532,7 +533,7 @@
 ################################################################################
 # Test dependencies
 
-pallet-test-utils = { optional = true, default-features = false, path = "../../test-pallets/utils" }
+pallet-test-utils = { default-features = false, path = "../../test-pallets/utils" }
 
 ################################################################################
 # Other Dependencies
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -65,7 +65,7 @@
 	pub const ChainId: u64 = 8882;
 }
 
-construct_runtime!(opal);
+construct_runtime!();
 
 impl_common_runtime_apis!();
 
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -524,6 +524,11 @@
 num_enum = { version = "0.5.3", default-features = false }
 
 ################################################################################
+# Test dependencies
+
+pallet-test-utils = { default-features = false, path = "../../test-pallets/utils" }
+
+################################################################################
 # Other Dependencies
 
 impl-trait-for-tuples = "0.2.2"
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
77 pub const ChainId: u64 = 8881;77 pub const ChainId: u64 = 8881;
78}78}
7979
80construct_runtime!(quartz);80construct_runtime!();
8181
82impl_common_runtime_apis!();82impl_common_runtime_apis!();
8383
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -516,6 +516,11 @@
 num_enum = { version = "0.5.3", default-features = false }
 
 ################################################################################
+# Test dependencies
+
+pallet-test-utils = { default-features = false, path = "../../test-pallets/utils" }
+
+################################################################################
 # Other Dependencies
 
 impl-trait-for-tuples = "0.2.2"
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -65,7 +65,7 @@
 	pub const ChainId: u64 = 8880;
 }
 
-construct_runtime!(unique);
+construct_runtime!();
 
 impl_common_runtime_apis!();