-
Notifications
You must be signed in to change notification settings - Fork 300
Add a filter for filtering unsupported MultiLocation
#714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
3a29f10
5cd065f
f4b955c
c7c36e8
32bb4c9
f22500c
eed40a2
8ff5aa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ use crate as orml_xtokens; | |
|
|
||
| use frame_support::{ | ||
| construct_runtime, parameter_types, | ||
| traits::{Everything, Get, Nothing}, | ||
| traits::{Contains, Everything, Get, Nothing}, | ||
| weights::{constants::WEIGHT_PER_SECOND, Weight}, | ||
| }; | ||
| use frame_system::EnsureRoot; | ||
|
|
@@ -270,6 +270,52 @@ parameter_types! { | |
| pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); | ||
| pub const BaseXcmWeight: Weight = 100_000_000; | ||
| pub const MaxAssetsForTransfer: usize = 3; | ||
| pub SupportedMultiLocations: Vec<MultiLocation> = vec![ | ||
| MultiLocation::new( | ||
| 1, | ||
| X1(Parachain(1)) | ||
| ), | ||
| MultiLocation::new( | ||
| 1, | ||
| X1(Parachain(2)) | ||
| ), | ||
| MultiLocation::new( | ||
| 1, | ||
| X1(Parachain(3)) | ||
| ), | ||
| // There's a test that uses para id = 100 | ||
| MultiLocation::new( | ||
| 1, | ||
| X1(Parachain(100)) | ||
| ) | ||
| ]; | ||
| } | ||
|
|
||
| pub struct WhiteListingMultiLocations; | ||
| impl Contains<MultiLocation> for WhiteListingMultiLocations { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could offer some default implementation(in trait/location.rs), and use Tuple combine with fall-through way. i.e.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or a simple way like: if allow local asset:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot use |
||
| fn contains(dest: &MultiLocation) -> bool { | ||
| if dest.parent_count() != 1 { | ||
| return false; | ||
| } | ||
|
|
||
| if let Junctions::X1(Junction::AccountId32 { .. }) = dest.interior() { | ||
| // parent = 1, and the junctions is the variant X1 | ||
| // means the asset will be sent to relaychain. | ||
| true | ||
| } else { | ||
| // if the asset is sent to parachain, | ||
| // the junctions must have the variant Parachain | ||
| dest.interior().iter().any(|i| match i { | ||
| Junction::Parachain(parachain_id) => SupportedMultiLocations::get().iter().any(|location| { | ||
| location | ||
| .interior | ||
| .iter() | ||
| .any(|junc| *junc == Junction::Parachain(*parachain_id)) | ||
| }), | ||
| _ => false, // No parachain id found. | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| parameter_type_with_key! { | ||
|
|
@@ -289,6 +335,7 @@ impl orml_xtokens::Config for Runtime { | |
| type CurrencyIdConvert = CurrencyIdConvert; | ||
| type AccountIdToMultiLocation = AccountIdToMultiLocation; | ||
| type SelfLocation = SelfLocation; | ||
| type MultiLocationsFilter = WhiteListingMultiLocations; | ||
| type MinXcmFee = ParachainMinFee; | ||
| type XcmExecutor = XcmExecutor<XcmConfig>; | ||
| type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1335,3 +1335,32 @@ fn send_with_zero_amount() { | |
|
|
||
| // TODO: should have more tests after https://github.com/paritytech/polkadot/issues/4996 | ||
| } | ||
|
|
||
| #[test] | ||
| fn unsupported_multilocation_should_be_filtered() { | ||
| TestNet::reset(); | ||
|
|
||
| ParaB::execute_with(|| { | ||
| assert_ok!(ParaTokens::deposit(CurrencyId::B, &ALICE, 1_000)); | ||
| assert_noop!( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more test with |
||
| ParaXTokens::transfer( | ||
| Some(ALICE).into(), | ||
| CurrencyId::B, | ||
| 500, | ||
| Box::new( | ||
| ( | ||
| Parent, | ||
| Parachain(4), // parachain 4 is not supported list. | ||
| Junction::AccountId32 { | ||
| network: NetworkId::Any, | ||
| id: BOB.into(), | ||
| }, | ||
| ) | ||
| .into() | ||
| ), | ||
| 40, | ||
| ), | ||
| Error::<para::Runtime>::NotSupportedMultiLocation | ||
| ); | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.