Skip to content

Commit eed40a2

Browse files
committed
Add filter check to do_transfer_multiassets and update related test case
Signed-off-by: Dengjianping <[email protected]>
1 parent f22500c commit eed40a2

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

xtokens/src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ pub mod module {
458458
currencies.len() <= T::MaxAssetsForTransfer::get(),
459459
Error::<T>::TooManyAssetsBeingSent
460460
);
461+
ensure!(
462+
T::MultiLocationsFilter::contains(&dest),
463+
Error::<T>::NotSupportedMultiLocation
464+
);
461465

462466
let mut assets = MultiAssets::new();
463467

@@ -470,10 +474,6 @@ pub mod module {
470474
let location: MultiLocation = T::CurrencyIdConvert::convert(currency_id.clone())
471475
.ok_or(Error::<T>::NotCrossChainTransferableCurrency)?;
472476
ensure!(!amount.is_zero(), Error::<T>::ZeroAmount);
473-
ensure!(
474-
T::MultiLocationsFilter::contains(&dest),
475-
Error::<T>::NotSupportedMultiLocation
476-
);
477477

478478
// Push contains saturated addition, so we should be able to use it safely
479479
assets.push((location, (*amount).into()).into())
@@ -500,6 +500,10 @@ pub mod module {
500500
assets.len() <= T::MaxAssetsForTransfer::get(),
501501
Error::<T>::TooManyAssetsBeingSent
502502
);
503+
ensure!(
504+
T::MultiLocationsFilter::contains(&dest),
505+
Error::<T>::NotSupportedMultiLocation
506+
);
503507
let origin_location = T::AccountIdToMultiLocation::convert(who.clone());
504508

505509
let mut non_fee_reserve: Option<MultiLocation> = None;

xtokens/src/mock/para.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,13 @@ parameter_types! {
294294
pub struct WhiteListingMultiLocations;
295295
impl Contains<MultiLocation> for WhiteListingMultiLocations {
296296
fn contains(dest: &MultiLocation) -> bool {
297-
if dest.parent_count() != 1 {
297+
// Consider children parachain, means parent = 0
298+
if dest.parent_count() != 0 && dest.parent_count() != 1 {
298299
return false;
299300
}
300301

301302
if let Junctions::X1(Junction::AccountId32 { .. }) = dest.interior() {
302-
// parent = 1, and the junctions is the variant X1
303+
// parent = 1 or 0, and the junctions is the variant X1
303304
// means the asset will be sent to relaychain.
304305
true
305306
} else {

xtokens/src/tests.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ fn unsupported_multilocation_should_be_filtered() {
13421342

13431343
ParaB::execute_with(|| {
13441344
assert_ok!(ParaTokens::deposit(CurrencyId::B, &ALICE, 1_000));
1345+
assert_ok!(ParaTokens::deposit(CurrencyId::B1, &ALICE, 1_000));
13451346
assert_noop!(
13461347
ParaXTokens::transfer(
13471348
Some(ALICE).into(),
@@ -1362,5 +1363,26 @@ fn unsupported_multilocation_should_be_filtered() {
13621363
),
13631364
Error::<para::Runtime>::NotSupportedMultiLocation
13641365
);
1366+
1367+
assert_noop!(
1368+
ParaXTokens::transfer_multicurrencies(
1369+
Some(ALICE).into(),
1370+
vec![(CurrencyId::B1, 50), (CurrencyId::B, 450)],
1371+
0,
1372+
Box::new(
1373+
(
1374+
Parent,
1375+
Parachain(4),
1376+
Junction::AccountId32 {
1377+
network: NetworkId::Any,
1378+
id: BOB.into(),
1379+
},
1380+
)
1381+
.into()
1382+
),
1383+
40,
1384+
),
1385+
Error::<para::Runtime>::NotSupportedMultiLocation
1386+
);
13651387
});
13661388
}

0 commit comments

Comments
 (0)