difftreelog
Merge pull request #821 from UniqueNetwork/refactor/simplify-construct-runtime-macro
in: master
Simplify construct runtime macro
11 files changed
Cargo.lockdiffbeforeafterboth8942 "pallet-structure",8942 "pallet-structure",8943 "pallet-sudo",8943 "pallet-sudo",8944 "pallet-template-transaction-payment",8944 "pallet-template-transaction-payment",8945 "pallet-test-utils",8945 "pallet-timestamp",8946 "pallet-timestamp",8946 "pallet-transaction-payment",8947 "pallet-transaction-payment",8947 "pallet-transaction-payment-rpc-runtime-api",8948 "pallet-transaction-payment-rpc-runtime-api",13174 "pallet-structure",13175 "pallet-structure",13175 "pallet-sudo",13176 "pallet-sudo",13176 "pallet-template-transaction-payment",13177 "pallet-template-transaction-payment",13178 "pallet-test-utils",13177 "pallet-timestamp",13179 "pallet-timestamp",13178 "pallet-transaction-payment",13180 "pallet-transaction-payment",13179 "pallet-transaction-payment-rpc-runtime-api",13181 "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.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)*)
- }
- };
-}
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!();