Skip to content

Commit 8ff5aa1

Browse files
committed
Use macro match_type
Signed-off-by: Dengjianping <[email protected]>
1 parent eed40a2 commit 8ff5aa1

File tree

1 file changed

+12
-48
lines changed

1 file changed

+12
-48
lines changed

xtokens/src/mock/para.rs

+12-48
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::{Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter};
22
use crate as orml_xtokens;
33

44
use frame_support::{
5-
construct_runtime, parameter_types,
6-
traits::{Contains, Everything, Get, Nothing},
5+
construct_runtime, match_type, parameter_types,
6+
traits::{Everything, Get, Nothing},
77
weights::{constants::WEIGHT_PER_SECOND, Weight},
88
};
99
use frame_system::EnsureRoot;
@@ -270,53 +270,17 @@ parameter_types! {
270270
pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
271271
pub const BaseXcmWeight: Weight = 100_000_000;
272272
pub const MaxAssetsForTransfer: usize = 3;
273-
pub SupportedMultiLocations: Vec<MultiLocation> = vec![
274-
MultiLocation::new(
275-
1,
276-
X1(Parachain(1))
277-
),
278-
MultiLocation::new(
279-
1,
280-
X1(Parachain(2))
281-
),
282-
MultiLocation::new(
283-
1,
284-
X1(Parachain(3))
285-
),
286-
// There's a test that uses para id = 100
287-
MultiLocation::new(
288-
1,
289-
X1(Parachain(100))
290-
)
291-
];
292273
}
293274

294-
pub struct WhiteListingMultiLocations;
295-
impl Contains<MultiLocation> for WhiteListingMultiLocations {
296-
fn contains(dest: &MultiLocation) -> bool {
297-
// Consider children parachain, means parent = 0
298-
if dest.parent_count() != 0 && dest.parent_count() != 1 {
299-
return false;
300-
}
301-
302-
if let Junctions::X1(Junction::AccountId32 { .. }) = dest.interior() {
303-
// parent = 1 or 0, and the junctions is the variant X1
304-
// means the asset will be sent to relaychain.
305-
true
306-
} else {
307-
// if the asset is sent to parachain,
308-
// the junctions must have the variant Parachain
309-
dest.interior().iter().any(|i| match i {
310-
Junction::Parachain(parachain_id) => SupportedMultiLocations::get().iter().any(|location| {
311-
location
312-
.interior
313-
.iter()
314-
.any(|junc| *junc == Junction::Parachain(*parachain_id))
315-
}),
316-
_ => false, // No parachain id found.
317-
})
318-
}
319-
}
275+
match_type! {
276+
pub type ParentOrParachains: impl Contains<MultiLocation> = {
277+
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { .. }) } |
278+
MultiLocation { parents: 1, interior: X1(Junction::AccountId32 { .. }) } |
279+
MultiLocation { parents: 1, interior: X2(Parachain(1), Junction::AccountId32 { .. }) } |
280+
MultiLocation { parents: 1, interior: X2(Parachain(2), Junction::AccountId32 { .. }) } |
281+
MultiLocation { parents: 1, interior: X2(Parachain(3), Junction::AccountId32 { .. }) } |
282+
MultiLocation { parents: 1, interior: X2(Parachain(100), Junction::AccountId32 { .. }) }
283+
};
320284
}
321285

322286
parameter_type_with_key! {
@@ -336,7 +300,7 @@ impl orml_xtokens::Config for Runtime {
336300
type CurrencyIdConvert = CurrencyIdConvert;
337301
type AccountIdToMultiLocation = AccountIdToMultiLocation;
338302
type SelfLocation = SelfLocation;
339-
type MultiLocationsFilter = WhiteListingMultiLocations;
303+
type MultiLocationsFilter = ParentOrParachains;
340304
type MinXcmFee = ParachainMinFee;
341305
type XcmExecutor = XcmExecutor<XcmConfig>;
342306
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;

0 commit comments

Comments
 (0)