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]
18
macro_rules! impl_self_contained_call {
19
	{} => {
20
		impl fp_self_contained::SelfContainedCall for RuntimeCall {
21
			type SignedInfo = H160;
22

            
23
180
			fn is_self_contained(&self) -> bool {
24
180
				match self {
25
120
					RuntimeCall::Ethereum(call) => call.is_self_contained(),
26
60
					_ => false,
27
				}
28
180
			}
29
180

            
30
180
			fn check_self_contained(
31
120
				&self
32
120
			) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {
33
120
				match self {
34
120
					RuntimeCall::Ethereum(call) => call.check_self_contained(),
35
					_ => None,
36
				}
37
120
			}
38
120

            
39
120
			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
120
			fn pre_dispatch_self_contained(
52
120
				&self,
53
120
				info: &Self::SignedInfo,
54
120
				dispatch_info: &DispatchInfoOf<RuntimeCall>,
55
120
				len: usize,
56
120
			) -> Option<Result<(), TransactionValidityError>> {
57
120
				match self {
58
120
					RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len),
59
					_ => None,
60
				}
61
120
			}
62
120

            
63
120
			fn apply_self_contained(
64
40
				self,
65
40
				info: Self::SignedInfo,
66
40
			) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {
67
40
				match self {
68
40
					call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(
69
40
						call.dispatch(RuntimeOrigin::from(
70
40
							pallet_ethereum::RawOrigin::EthereumTransaction(info)
71
40
						))
72
40
					),
73
					_ => None,
74
				}
75
			}
76
		}
77
	}
78
}