diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 6ec878506a11ea9fa06b155f9e75c5e4d2a159cd..ea2971856503eb90b59c48a6467a8e9cab1c9ca1 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -22,6 +22,7 @@ pub mod constants; pub mod entities; pub mod fees; pub mod handlers; +mod offchain; mod pallets_config; pub mod providers; diff --git a/runtime/common/src/offchain.rs b/runtime/common/src/offchain.rs new file mode 100644 index 0000000000000000000000000000000000000000..aa857c51b1743a619560bb9d745c451b804bb06d --- /dev/null +++ b/runtime/common/src/offchain.rs @@ -0,0 +1,48 @@ +// Copyright 2021 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#[macro_export] +macro_rules! offchain_config { + () => { + impl<LocalCall> frame_system::offchain::CreateTransaction<LocalCall> for Runtime + where + RuntimeCall: From<LocalCall>, + { + type Extension = TxExtension; + + fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic { + generic::UncheckedExtrinsic::new_transaction(call, extension) + } + } + + impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Runtime + where + RuntimeCall: From<LocalCall>, + { + fn create_inherent(call: RuntimeCall) -> UncheckedExtrinsic { + generic::UncheckedExtrinsic::new_bare(call) + } + } + + impl<LocalCall> frame_system::offchain::CreateTransactionBase<LocalCall> for Runtime + where + RuntimeCall: From<LocalCall>, + { + type Extrinsic = UncheckedExtrinsic; + type RuntimeCall = RuntimeCall; + } + }; +} diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index b448658a25a4ba7b84ab6987d615fbba2179228c..91f34c21df1664591257fa1dd9621130864d8b4a 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -73,8 +73,6 @@ pub use frame_support::{ StorageValue, }; -common_runtime::declare_session_keys! {} - // To learn more about runtime versioning and what each of the following value means: // https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning #[sp_version::runtime_version] @@ -131,8 +129,6 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -common_runtime::benchmarks_config!(); - pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { fn contains(call: &RuntimeCall) -> bool { @@ -193,9 +189,6 @@ impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType { } } -// Configure pallets to include in runtime. -common_runtime::pallets_config!(); - // Create the runtime by composing the pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -252,42 +245,11 @@ construct_runtime!( } ); -impl<LocalCall> frame_system::offchain::CreateTransaction<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - type Extension = TxExtension; - - fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_transaction(call, extension) - } -} - -impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - fn create_inherent(call: RuntimeCall) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_bare(call) - } -} - -impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime -where - RuntimeCall: From<C>, -{ - type Extrinsic = UncheckedExtrinsic; - type RuntimeCall = RuntimeCall; -} - // All of our runtimes share most of their Runtime API implementations. // We use a macro to implement this common part and add runtime-specific additional implementations. -// This macro expands to : -// ``` -// impl_runtime_apis! { -// // All impl blocks shared between all runtimes. -// -// // Specific impls provided to the `runtime_apis!` macro. -// } -// ``` +common_runtime::pallets_config!(); +common_runtime::declare_session_keys! {} +#[cfg(feature = "runtime-benchmarks")] +common_runtime::benchmarks_config!(); +common_runtime::offchain_config! {} common_runtime::runtime_apis! {} diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 7d2b5a2c7bb6a054ecd40a8d65a51fb2e89d9c0a..71d340ecea638f95e4ac122c7da9a817244dabba 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -73,8 +73,6 @@ pub use frame_support::{ StorageValue, }; -common_runtime::declare_session_keys! {} - // To learn more about runtime versioning and what each of the following value means: // https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning #[sp_version::runtime_version] @@ -132,8 +130,6 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -common_runtime::benchmarks_config!(); - pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { fn contains(call: &RuntimeCall) -> bool { @@ -235,7 +231,6 @@ impl pallet_duniter_test_parameters::Config for Runtime { type PeriodCount = Balance; type SessionCount = u32; } -common_runtime::pallets_config!(); // Create the runtime by composing the pallets that were previously configured. construct_runtime!( @@ -295,42 +290,11 @@ construct_runtime!( } ); -impl<LocalCall> frame_system::offchain::CreateTransaction<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - type Extension = TxExtension; - - fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_transaction(call, extension) - } -} - -impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - fn create_inherent(call: RuntimeCall) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_bare(call) - } -} - -impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime -where - RuntimeCall: From<C>, -{ - type Extrinsic = UncheckedExtrinsic; - type RuntimeCall = RuntimeCall; -} - // All of our runtimes share most of their Runtime API implementations. // We use a macro to implement this common part and add runtime-specific additional implementations. -// This macro expands to : -// ``` -// impl_runtime_apis! { -// // All impl blocks shared between all runtimes. -// -// // Specific impls provided to the `runtime_apis!` macro. -// } -// ``` +common_runtime::pallets_config!(); +common_runtime::declare_session_keys! {} +#[cfg(feature = "runtime-benchmarks")] +common_runtime::benchmarks_config!(); +common_runtime::offchain_config! {} common_runtime::runtime_apis! {} diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 518e9b8387277e062e7db2fd8e0573d069abe650..6876b754ab58cee5cd2e86b39c0cafe03fe9cd52 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -72,8 +72,6 @@ pub use frame_support::{ StorageValue, }; -common_runtime::declare_session_keys! {} - // To learn more about runtime versioning and what each of the following value means: // https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning #[sp_version::runtime_version] @@ -131,8 +129,6 @@ pub type Executive = frame_executive::Executive< pub type TechnicalCommitteeInstance = Instance2; -common_runtime::benchmarks_config!(); - pub struct BaseCallFilter; impl Contains<RuntimeCall> for BaseCallFilter { fn contains(call: &RuntimeCall) -> bool { @@ -200,9 +196,6 @@ impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType { } } -// Configure pallets to include in runtime. -common_runtime::pallets_config!(); - // Create the runtime by composing the pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -259,42 +252,11 @@ construct_runtime!( } ); -impl<LocalCall> frame_system::offchain::CreateTransaction<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - type Extension = TxExtension; - - fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_transaction(call, extension) - } -} - -impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Runtime -where - RuntimeCall: From<LocalCall>, -{ - fn create_inherent(call: RuntimeCall) -> UncheckedExtrinsic { - generic::UncheckedExtrinsic::new_bare(call) - } -} - -impl<C> frame_system::offchain::CreateTransactionBase<C> for Runtime -where - RuntimeCall: From<C>, -{ - type Extrinsic = UncheckedExtrinsic; - type RuntimeCall = RuntimeCall; -} - // All of our runtimes share most of their Runtime API implementations. // We use a macro to implement this common part and add runtime-specific additional implementations. -// This macro expands to : -// ``` -// impl_runtime_apis! { -// // All impl blocks shared between all runtimes. -// -// // Specific impls provided to the `runtime_apis!` macro. -// } -// ``` +common_runtime::pallets_config!(); +common_runtime::declare_session_keys! {} +#[cfg(feature = "runtime-benchmarks")] +common_runtime::benchmarks_config!(); +common_runtime::offchain_config! {} common_runtime::runtime_apis! {}