xcm_primitives/
filter_asset_max_fee.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
17use frame_support::traits::Get;
18use xcm::latest::Asset;
19use xcm_builder::Case;
20
21/// Filters max fee for a given multiasset.
22/// It takes self (a multiasset) and runs contains in the argument multiasset
23/// Can be amalgamated into tuples.
24/// If any item returns `true`, it short-circuits, else `false` is returned.
25pub trait FilterMaxAssetFee {
26	/// A filter to be able to compare against a max asset.
27	fn filter_max_asset_fee(asset: &Asset) -> bool;
28}
29
30#[impl_trait_for_tuples::impl_for_tuples(30)]
31impl FilterMaxAssetFee for Tuple {
32	fn filter_max_asset_fee(what: &Asset) -> bool {
33		for_tuples!( #(
34			if Tuple::filter_max_asset_fee(what) { return true }
35		)* );
36		log::trace!(
37			target: "xcm::filter_max_asset_fee",
38			"got filtered: what: {:?}",
39			what,
40		);
41		false
42	}
43}
44
45impl<T: Get<Asset>> FilterMaxAssetFee for Case<T> {
46	fn filter_max_asset_fee(asset: &Asset) -> bool {
47		log::trace!(target: "xcm::filter_max_asset_fee", "Case asset: {:?}", asset);
48		let max = T::get();
49		max.contains(asset)
50	}
51}