From dae3f31e67dec5346eb933967469b4ae8dce0c8d Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Feb 2023 17:39:51 +0800 Subject: [PATCH] Use `impl_self_contained_call` (#250) --- runtime/common/src/lib.rs | 74 +++++++++++++++++++++++++++++++++++++ runtime/crab/src/lib.rs | 62 +------------------------------ runtime/darwinia/src/lib.rs | 64 +------------------------------- runtime/pangolin/src/lib.rs | 62 +------------------------------ 4 files changed, 78 insertions(+), 184 deletions(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 4a070a3ef..5bb1198cd 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -86,3 +86,77 @@ pub const fn darwinia_deposit(items: u32, bytes: u32) -> Balance { items as Balance * 100 * UNIT + (bytes as Balance) * 100 * MICROUNIT // items as Balance * 100 * UNIT + (bytes as Balance) * 100 * MILLIUNIT } + +#[macro_export] +macro_rules! impl_self_contained_call { + () => { + impl fp_self_contained::SelfContainedCall for RuntimeCall { + type SignedInfo = H160; + + fn is_self_contained(&self) -> bool { + match self { + RuntimeCall::Ethereum(call) => call.is_self_contained(), + _ => false, + } + } + + fn check_self_contained( + &self, + ) -> Option< + Result< + Self::SignedInfo, + sp_runtime::transaction_validity::TransactionValidityError, + >, + > { + match self { + RuntimeCall::Ethereum(call) => call.check_self_contained(), + _ => None, + } + } + + fn validate_self_contained( + &self, + info: &Self::SignedInfo, + dispatch_info: &sp_runtime::traits::DispatchInfoOf, + len: usize, + ) -> Option { + match self { + RuntimeCall::Ethereum(call) => + call.validate_self_contained(info, dispatch_info, len), + _ => None, + } + } + + fn pre_dispatch_self_contained( + &self, + info: &Self::SignedInfo, + dispatch_info: &sp_runtime::traits::DispatchInfoOf, + len: usize, + ) -> Option> { + match self { + RuntimeCall::Ethereum(call) => + call.pre_dispatch_self_contained(info, dispatch_info, len), + _ => None, + } + } + + fn apply_self_contained( + self, + info: Self::SignedInfo, + ) -> Option< + sp_runtime::DispatchResultWithInfo>, + > { + // substrate + use sp_runtime::traits::Dispatchable; + + match self { + call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => + Some(call.dispatch(RuntimeOrigin::from( + pallet_ethereum::RawOrigin::EthereumTransaction(info), + ))), + _ => None, + } + } + } + }; +} diff --git a/runtime/crab/src/lib.rs b/runtime/crab/src/lib.rs index b71616cad..5be6235e2 100644 --- a/runtime/crab/src/lib.rs +++ b/runtime/crab/src/lib.rs @@ -144,67 +144,7 @@ where } } -impl fp_self_contained::SelfContainedCall for RuntimeCall { - type SignedInfo = H160; - - fn is_self_contained(&self) -> bool { - match self { - RuntimeCall::Ethereum(call) => call.is_self_contained(), - _ => false, - } - } - - fn check_self_contained( - &self, - ) -> Option> - { - match self { - RuntimeCall::Ethereum(call) => call.check_self_contained(), - _ => None, - } - } - - fn validate_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option { - match self { - RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn pre_dispatch_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option> { - match self { - RuntimeCall::Ethereum(call) => - call.pre_dispatch_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn apply_self_contained( - self, - info: Self::SignedInfo, - ) -> Option>> { - // substrate - use sp_runtime::traits::Dispatchable; - - match self { - call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => - Some(call.dispatch(RuntimeOrigin::from( - pallet_ethereum::RawOrigin::EthereumTransaction(info), - ))), - _ => None, - } - } -} +impl_self_contained_call!(); /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] diff --git a/runtime/darwinia/src/lib.rs b/runtime/darwinia/src/lib.rs index d7106e742..f0b213f0d 100644 --- a/runtime/darwinia/src/lib.rs +++ b/runtime/darwinia/src/lib.rs @@ -144,74 +144,14 @@ where } } -impl fp_self_contained::SelfContainedCall for RuntimeCall { - type SignedInfo = H160; - - fn is_self_contained(&self) -> bool { - match self { - RuntimeCall::Ethereum(call) => call.is_self_contained(), - _ => false, - } - } - - fn check_self_contained( - &self, - ) -> Option> - { - match self { - RuntimeCall::Ethereum(call) => call.check_self_contained(), - _ => None, - } - } - - fn validate_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option { - match self { - RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn pre_dispatch_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option> { - match self { - RuntimeCall::Ethereum(call) => - call.pre_dispatch_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn apply_self_contained( - self, - info: Self::SignedInfo, - ) -> Option>> { - // substrate - use sp_runtime::traits::Dispatchable; - - match self { - call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => - Some(call.dispatch(RuntimeOrigin::from( - pallet_ethereum::RawOrigin::EthereumTransaction(info), - ))), - _ => None, - } - } -} - /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } +impl_self_contained_call!(); + // Create the runtime by composing the FRAME pallets that were previously configured. frame_support::construct_runtime! { pub enum Runtime where diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 85befb0c5..c59b40a89 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -141,67 +141,7 @@ where } } -impl fp_self_contained::SelfContainedCall for RuntimeCall { - type SignedInfo = H160; - - fn is_self_contained(&self) -> bool { - match self { - RuntimeCall::Ethereum(call) => call.is_self_contained(), - _ => false, - } - } - - fn check_self_contained( - &self, - ) -> Option> - { - match self { - RuntimeCall::Ethereum(call) => call.check_self_contained(), - _ => None, - } - } - - fn validate_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option { - match self { - RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn pre_dispatch_self_contained( - &self, - info: &Self::SignedInfo, - dispatch_info: &sp_runtime::traits::DispatchInfoOf, - len: usize, - ) -> Option> { - match self { - RuntimeCall::Ethereum(call) => - call.pre_dispatch_self_contained(info, dispatch_info, len), - _ => None, - } - } - - fn apply_self_contained( - self, - info: Self::SignedInfo, - ) -> Option>> { - // substrate - use sp_runtime::traits::Dispatchable; - - match self { - call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => - Some(call.dispatch(RuntimeOrigin::from( - pallet_ethereum::RawOrigin::EthereumTransaction(info), - ))), - _ => None, - } - } -} +impl_self_contained_call!(); /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")]