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