1
// Copyright 2019-2022 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
396
			fn is_self_contained(&self) -> bool {
24
396
				match self {
25
264
					RuntimeCall::Ethereum(call) => call.is_self_contained(),
26
132
					_ => false,
27
				}
28
396
			}
29
396

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

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

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