This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Use FromNetwork #80
Merged
Merged
Use FromNetwork #80
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation> | |
} | ||
} | ||
|
||
/// Checks if `a` is from the expected global consensus network. Checks that `MultiLocation-a` | ||
/// starts with `MultiLocation-b`, and that network is a foreign consensus system. | ||
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>( | ||
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>, | ||
); | ||
|
@@ -72,6 +74,7 @@ impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<Netwo | |
|
||
let universal_source = UniversalLocation::get(); | ||
|
||
// ensure that `a`` is remote and from the expected network | ||
match ensure_is_remote(universal_source, a) { | ||
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(), | ||
Err(e) => { | ||
|
@@ -85,6 +88,7 @@ impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<Netwo | |
} | ||
} | ||
} | ||
|
||
/// Adapter verifies if it is allowed to receive `MultiAsset` from `MultiLocation`. | ||
/// | ||
/// Note: `MultiLocation` has to be from a different global consensus. | ||
|
@@ -122,3 +126,92 @@ impl< | |
Reserves::contains(asset, origin) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use frame_support::parameter_types; | ||
|
||
parameter_types! { | ||
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(Rococo), Parachain(1000)); | ||
pub ExpectedNetworkId: NetworkId = Wococo; | ||
} | ||
|
||
#[test] | ||
fn from_network_contains_works() { | ||
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. 🥳 |
||
// asset and origin from foreign consensus works | ||
let asset: MultiLocation = ( | ||
Parent, | ||
Parent, | ||
GlobalConsensus(Wococo), | ||
Parachain(1000), | ||
PalletInstance(1), | ||
GeneralIndex(1), | ||
) | ||
.into(); | ||
let origin: MultiLocation = | ||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into(); | ||
assert!(FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
|
||
// asset and origin from local consensus fails | ||
let asset: MultiLocation = ( | ||
Parent, | ||
Parent, | ||
GlobalConsensus(Rococo), | ||
Parachain(1000), | ||
PalletInstance(1), | ||
GeneralIndex(1), | ||
) | ||
.into(); | ||
let origin: MultiLocation = | ||
(Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into(); | ||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
|
||
// asset and origin from here fails | ||
let asset: MultiLocation = (PalletInstance(1), GeneralIndex(1)).into(); | ||
let origin: MultiLocation = Here.into(); | ||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
|
||
// asset from different consensus fails | ||
let asset: MultiLocation = ( | ||
Parent, | ||
Parent, | ||
GlobalConsensus(Polkadot), | ||
Parachain(1000), | ||
PalletInstance(1), | ||
GeneralIndex(1), | ||
) | ||
.into(); | ||
let origin: MultiLocation = | ||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into(); | ||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
|
||
// origin from different consensus fails | ||
let asset: MultiLocation = ( | ||
Parent, | ||
Parent, | ||
GlobalConsensus(Wococo), | ||
Parachain(1000), | ||
PalletInstance(1), | ||
GeneralIndex(1), | ||
) | ||
.into(); | ||
let origin: MultiLocation = | ||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); | ||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
|
||
// asset and origin from unexpected consensus fails | ||
let asset: MultiLocation = ( | ||
Parent, | ||
Parent, | ||
GlobalConsensus(Polkadot), | ||
Parachain(1000), | ||
PalletInstance(1), | ||
GeneralIndex(1), | ||
) | ||
.into(); | ||
let origin: MultiLocation = | ||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into(); | ||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, its basically the equivalent of
Because
EthereumLocation.get().interior
isGlobalConsensus(Ethereum { chain_id: .. })
, then wesplit_global()
which strips the first global consensus part, leaving( GlobalConsensus(Ethereum { chain_id: .. }) , Junctions::Here )
. Then we take the second member of the tuple with.1
.