1234567891011121314151617use sp_core::H160;18use sp_runtime::{19 traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf},20 transaction_validity::{InvalidTransaction, TransactionValidity, TransactionValidityError},21};2223use crate::{Maintenance, RuntimeCall, RuntimeOrigin};2425impl fp_self_contained::SelfContainedCall for RuntimeCall {26 type SignedInfo = H160;2728 fn is_self_contained(&self) -> bool {29 match self {30 RuntimeCall::Ethereum(call) => call.is_self_contained(),31 _ => false,32 }33 }3435 fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {36 match self {37 RuntimeCall::Ethereum(call) => {38 if Maintenance::is_enabled() {39 Some(Err(TransactionValidityError::Invalid(40 InvalidTransaction::Call,41 )))42 } else {43 call.check_self_contained()44 }45 }46 _ => None,47 }48 }4950 fn validate_self_contained(51 &self,52 info: &Self::SignedInfo,53 dispatch_info: &DispatchInfoOf<RuntimeCall>,54 len: usize,55 ) -> Option<TransactionValidity> {56 match self {57 RuntimeCall::Ethereum(call) => {58 if Maintenance::is_enabled() {59 Some(Err(TransactionValidityError::Invalid(60 InvalidTransaction::Call,61 )))62 } else {63 call.validate_self_contained(info, dispatch_info, len)64 }65 }66 _ => None,67 }68 }6970 fn pre_dispatch_self_contained(71 &self,72 info: &Self::SignedInfo,73 dispatch_info: &DispatchInfoOf<RuntimeCall>,74 len: usize,75 ) -> Option<Result<(), TransactionValidityError>> {76 match self {77 RuntimeCall::Ethereum(call) => {78 call.pre_dispatch_self_contained(info, dispatch_info, len)79 }80 _ => None,81 }82 }8384 fn apply_self_contained(85 self,86 info: Self::SignedInfo,87 ) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {88 match self {89 call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => {90 Some(call.dispatch(RuntimeOrigin::from(91 pallet_ethereum::RawOrigin::EthereumTransaction(info),92 )))93 }94 _ => None,95 }96 }97}