From a18bd7d9e3fa636b4c41f449ab0f43127557f038 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 02 Aug 2022 08:46:05 +0000 Subject: [PATCH] feat: common construct_runtime --- --- /dev/null +++ b/runtime/common/src/construct_runtime/mod.rs @@ -0,0 +1,72 @@ +mod util; + +#[macro_export] +macro_rules! construct_runtime { + () => { + $crate::construct_runtime_impl! { + pub enum Runtime where + Block = Block, + NodeBlock = opaque::Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event, ValidateUnsigned} = 20, + ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21, + + Aura: pallet_aura::{Pallet, Config} = 22, + AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23, + + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 30, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 33, + Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event} = 34, + Sudo: pallet_sudo::{Pallet, Call, Storage, Config, Event} = 35, + System: frame_system::{Pallet, Call, Storage, Config, Event} = 36, + Vesting: orml_vesting::{Pallet, Storage, Call, Event, Config} = 37, + // Vesting: pallet_vesting::{Pallet, Call, Config, Storage, Event} = 37, + // Contracts: pallet_contracts::{Pallet, Call, Storage, Event} = 38, + + // XCM helpers. + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 50, + PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin} = 51, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event, Origin} = 52, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 53, + + // Unique Pallets + Inflation: pallet_inflation::{Pallet, Call, Storage} = 60, + Unique: pallet_unique::{Pallet, Call, Storage, Event} = 61, + + #[runtimes(opal)] + Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event} = 62, + + // free = 63 + + Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64, + // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65, + Common: pallet_common::{Pallet, Storage, Event} = 66, + Fungible: pallet_fungible::{Pallet, Storage} = 67, + + #[runtimes(opal)] + Refungible: pallet_refungible::{Pallet, Storage} = 68, + + Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69, + Structure: pallet_structure::{Pallet, Call, Storage, Event} = 70, + + #[runtimes(opal)] + RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event} = 71, + + #[runtimes(opal)] + RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event} = 72, + + // Frontier + EVM: pallet_evm::{Pallet, Config, Call, Storage, Event} = 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} = 151, + EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152, + EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153, + } + } + } +} --- /dev/null +++ b/runtime/common/src/construct_runtime/util.rs @@ -0,0 +1,273 @@ +#[macro_export] +macro_rules! construct_runtime_impl { + ( + pub enum $runtime:ident 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! { + runtime($runtime), + where_clause($($where_ident = $where_ty),*), + pallets( + $( + $(#[runtimes($($pallet_runtimes),+)])? + $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index + ),*, + ), + + opal_pallets(), + quartz_pallets(), + unique_pallets(), + } + } +} + +#[macro_export] +macro_rules! construct_runtime_helper { + ( + runtime($runtime:ident), + 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), + 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), + 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)* + $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, + ), + } + }; + + ( + runtime($runtime:ident), + where_clause($($where_clause:tt)*), + pallets(), + + opal_pallets($($opal_pallets:tt)*), + quartz_pallets($($quartz_pallets:tt)*), + unique_pallets($($unique_pallets:tt)*), + ) => { + #[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 + $($where_clause)* + { + $($unique_pallets)* + } + } + }; +} + +#[macro_export] +macro_rules! add_runtime_specific_pallets { + ( + runtime($runtime:ident), + 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( + $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)*), + } + }; + + ( + runtime($runtime:ident), + 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( + $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)*), + } + }; + + ( + runtime($runtime:ident), + where_clause($($where_clause:tt)*), + pallets( + $pallet_name:ident: $pallet_mod:ident::{$($pallet_parts:ty),*} = $index:literal, + $($pallets_tl:tt)* + ), + + runtimes( + unique, + + $($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( + $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index, + $($pallets_tl)* + ), + + runtimes($($runtime_tl)*), + + opal_pallets($($opal_pallets)*), + quartz_pallets($($quartz_pallets)*), + unique_pallets( + $($unique_pallets)* + $pallet_name: $pallet_mod::{$($pallet_parts),*} = $index, + ), + } + }; + + ( + runtime($runtime:ident), + 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)*), + + opal_pallets($($opal_pallets)*), + quartz_pallets($($quartz_pallets)*), + unique_pallets($($unique_pallets)*), + } + }; +} -- gitstuff