moonbeam_runtime_common/
impl_moonbeam_xcm_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_moonbeam_xcm_call {
19	{} => {
20
21		pub struct MoonbeamCall;
22		impl CallDispatcher<RuntimeCall> for MoonbeamCall {
23			fn dispatch(
24				call: RuntimeCall,
25				origin: RuntimeOrigin,
26			) -> Result<
27					PostDispatchInfoOf<RuntimeCall>,
28					DispatchErrorWithPostInfo<PostDispatchInfoOf<RuntimeCall>>
29				> {
30				if let Ok(raw_origin) = TryInto::<RawOrigin<AccountId>>::try_into(origin.clone().caller) {
31					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							RawOrigin::Signed(account_id)
36						) => {
37							return RuntimeCall::dispatch(
38								call,
39								pallet_ethereum_xcm::Origin::XcmEthereumTransaction(
40									account_id.into()
41								).into()
42							);
43						},
44						_ => {}
45					}
46				}
47				RuntimeCall::dispatch(call, origin)
48			}
49		}
50	}
51}