moonbeam_runtime_common/
impl_self_contained_call.rs

1// Copyright 2019-2025 PureStake Inc.
2// This file is part of Moonbeam.
3
4// Moonbeam is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Moonbeam is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16
17#[macro_export]
18macro_rules! impl_self_contained_call {
19	{} => {
20		impl fp_self_contained::SelfContainedCall for RuntimeCall {
21			type SignedInfo = H160;
22
23			fn is_self_contained(&self) -> bool {
24				match self {
25					RuntimeCall::Ethereum(call) => call.is_self_contained(),
26					_ => false,
27				}
28			}
29
30			fn check_self_contained(
31				&self
32			) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {
33				match self {
34					RuntimeCall::Ethereum(call) => call.check_self_contained(),
35					_ => None,
36				}
37			}
38
39			fn validate_self_contained(
40				&self,
41				signed_info: &Self::SignedInfo,
42				dispatch_info: &DispatchInfoOf<RuntimeCall>,
43				len: usize,
44			) -> Option<TransactionValidity> {
45				match self {
46					RuntimeCall::Ethereum(call) => call.validate_self_contained(signed_info, dispatch_info, len),
47					_ => None,
48				}
49			}
50
51			fn pre_dispatch_self_contained(
52				&self,
53				info: &Self::SignedInfo,
54				dispatch_info: &DispatchInfoOf<RuntimeCall>,
55				len: usize,
56			) -> Option<Result<(), TransactionValidityError>> {
57				match self {
58					RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len),
59					_ => None,
60				}
61			}
62
63			fn apply_self_contained(
64				self,
65				info: Self::SignedInfo,
66			) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {
67				match self {
68					call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(
69						call.dispatch(RuntimeOrigin::from(
70							pallet_ethereum::RawOrigin::EthereumTransaction(info)
71						))
72					),
73					_ => None,
74				}
75			}
76		}
77	}
78}