difftreelog
Merge pull request #821 from UniqueNetwork/refactor/simplify-construct-runtime-macro
in: master
Simplify construct runtime macro
11 files changed
Cargo.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",
runtime/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,
+ }
+ }
+ }
+}
runtime/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,
- }
- }
- }
-}
runtime/common/construct_runtime/util.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#[macro_export]18macro_rules! construct_runtime_impl {19 (20 select_runtime($select_runtime:ident);2122 pub enum Runtime where23 $($where_ident:ident = $where_ty:ty),* $(,)?24 {25 $(26 $(#[runtimes($($pallet_runtimes:ident),+ $(,)?)])?27 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal28 ),*29 $(,)?30 }31 ) => {32 $crate::construct_runtime_helper! {33 select_runtime($select_runtime),34 selected_pallets(),3536 where_clause($($where_ident = $where_ty),*),37 pallets(38 $(39 $(#[runtimes($($pallet_runtimes),+)])?40 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index41 ),*,42 )43 }44 }45}4647#[macro_export]48macro_rules! construct_runtime_helper {49 (50 select_runtime($select_runtime:ident),51 selected_pallets($($selected_pallets:tt)*),5253 where_clause($($where_clause:tt)*),54 pallets(55 #[runtimes($($pallet_runtimes:ident),+)]56 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,5758 $($pallets_tl:tt)*59 )60 ) => {61 $crate::add_runtime_specific_pallets! {62 select_runtime($select_runtime),63 runtimes($($pallet_runtimes),+,),64 selected_pallets($($selected_pallets)*),6566 where_clause($($where_clause)*),67 pallets(68 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,69 $($pallets_tl)*70 )71 }72 };7374 (75 select_runtime($select_runtime:ident),76 selected_pallets($($selected_pallets:tt)*),7778 where_clause($($where_clause:tt)*),79 pallets(80 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,8182 $($pallets_tl:tt)*83 )84 ) => {85 $crate::construct_runtime_helper! {86 select_runtime($select_runtime),87 selected_pallets(88 $($selected_pallets)*89 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,90 ),9192 where_clause($($where_clause)*),93 pallets($($pallets_tl)*)94 }95 };9697 (98 select_runtime($select_runtime:ident),99 selected_pallets($($selected_pallets:tt)*),100101 where_clause($($where_clause:tt)*),102 pallets()103 ) => {104 frame_support::construct_runtime! {105 pub enum Runtime where106 $($where_clause)*107 {108 $($selected_pallets)*109 }110 }111 };112}113114#[macro_export]115macro_rules! add_runtime_specific_pallets {116 (117 select_runtime(opal),118 runtimes(opal, $($_runtime_tl:tt)*),119 selected_pallets($($selected_pallets:tt)*),120121 where_clause($($where_clause:tt)*),122 pallets(123 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,124 $($pallets_tl:tt)*125 )126 ) => {127 $crate::construct_runtime_helper! {128 select_runtime(opal),129 selected_pallets(130 $($selected_pallets)*131 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,132 ),133134 where_clause($($where_clause)*),135 pallets($($pallets_tl)*)136 }137 };138139 (140 select_runtime(quartz),141 runtimes(quartz, $($_runtime_tl:tt)*),142 selected_pallets($($selected_pallets:tt)*),143144 where_clause($($where_clause:tt)*),145 pallets(146 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,147 $($pallets_tl:tt)*148 )149 ) => {150 $crate::construct_runtime_helper! {151 select_runtime(quartz),152 selected_pallets(153 $($selected_pallets)*154 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,155 ),156157 where_clause($($where_clause)*),158 pallets($($pallets_tl)*)159 }160 };161162 (163 select_runtime(unique),164 runtimes(unique, $($_runtime_tl:tt)*),165 selected_pallets($($selected_pallets:tt)*),166167 where_clause($($where_clause:tt)*),168 pallets(169 $pallet_name:ident: $pallet_mod:ident$(::{$($pallet_parts:ty),*})? = $index:literal,170 $($pallets_tl:tt)*171 )172 ) => {173 $crate::construct_runtime_helper! {174 select_runtime(unique),175 selected_pallets(176 $($selected_pallets)*177 $pallet_name: $pallet_mod$(::{$($pallet_parts),*})? = $index,178 ),179180 where_clause($($where_clause)*),181 pallets($($pallets_tl)*)182 }183 };184185 (186 select_runtime($select_runtime:ident),187 runtimes($_current_runtime:ident, $($runtime_tl:tt)*),188 selected_pallets($($selected_pallets:tt)*),189190 where_clause($($where_clause:tt)*),191 pallets($($pallets:tt)*)192 ) => {193 $crate::add_runtime_specific_pallets! {194 select_runtime($select_runtime),195 runtimes($($runtime_tl)*),196 selected_pallets($($selected_pallets)*),197198 where_clause($($where_clause)*),199 pallets($($pallets)*)200 }201 };202203 (204 select_runtime($select_runtime:ident),205 runtimes(),206 selected_pallets($($selected_pallets:tt)*),207208 where_clause($($where_clause:tt)*),209 pallets(210 $_pallet_name:ident: $_pallet_mod:ident$(::{$($_pallet_parts:ty),*})? = $_index:literal,211 $($pallets_tl:tt)*212 )213 ) => {214 $crate::construct_runtime_helper! {215 select_runtime($select_runtime),216 selected_pallets($($selected_pallets)*),217218 where_clause($($where_clause)*),219 pallets($($pallets_tl)*)220 }221 };222}runtime/common/identity.rsdiffbeforeafterboth--- a/runtime/common/identity.rs
+++ b/runtime/common/identity.rs
@@ -21,11 +21,12 @@
use sp_runtime::{
traits::{DispatchInfoOf, SignedExtension},
- transaction_validity::{
- TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,
- },
+ transaction_validity::{TransactionValidity, ValidTransaction, TransactionValidityError},
};
+#[cfg(feature = "collator-selection")]
+use sp_runtime::transaction_validity::InvalidTransaction;
+
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct DisableIdentityCalls;
runtime/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
runtime/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!();
runtime/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"
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -77,7 +77,7 @@
pub const ChainId: u64 = 8881;
}
-construct_runtime!(quartz);
+construct_runtime!();
impl_common_runtime_apis!();
runtime/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"
runtime/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!();