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_moonbeam_xcm_call {
19
	{} => {
20

            
21
		pub struct MoonbeamCall;
22
		impl CallDispatcher<RuntimeCall> for MoonbeamCall {
23
15
			fn dispatch(
24
15
				call: RuntimeCall,
25
15
				origin: RuntimeOrigin,
26
15
			) -> Result<
27
15
					PostDispatchInfoOf<RuntimeCall>,
28
15
					DispatchErrorWithPostInfo<PostDispatchInfoOf<RuntimeCall>>
29
15
				> {
30
15
				if let Ok(raw_origin) = TryInto::<RawOrigin<AccountId>>::try_into(origin.clone().caller) {
31
15
					match (call.clone(), raw_origin) {
32
						(
33
							RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact { .. }) |
34
							RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact_through_proxy { .. }),
35
9
							RawOrigin::Signed(account_id)
36
9
						) => {
37
9
							return RuntimeCall::dispatch(
38
9
								call,
39
9
								pallet_ethereum_xcm::Origin::XcmEthereumTransaction(
40
9
									account_id.into()
41
9
								).into()
42
9
							);
43
						},
44
6
						_ => {}
45
					}
46
				}
47
6
				RuntimeCall::dispatch(call, origin)
48
			}
49
		}
50
	}
51
}