Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
7df0417b
Unverified
Commit
7df0417b
authored
1 year ago
by
Serban Iorga
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
XCM MultiAssets: sort after reanchoring (#2129)
Fixes https://github.com/paritytech/polkadot-sdk/issues/2123
parent
29b4bd42
No related merge requests found
Pipeline
#408569
canceled with stages
in 28 minutes and 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polkadot/xcm/src/v3/multiasset.rs
+41
-1
41 additions, 1 deletion
polkadot/xcm/src/v3/multiasset.rs
with
41 additions
and
1 deletion
polkadot/xcm/src/v3/multiasset.rs
+
41
−
1
View file @
7df0417b
...
...
@@ -689,12 +689,16 @@ impl MultiAssets {
/// Mutate the location of the asset identifier if concrete, giving it the same location
/// relative to a `target` context. The local context is provided as `context`.
///
/// This will also re-sort the inner assets to preserve ordering guarantees.
pub
fn
reanchor
(
&
mut
self
,
target
:
&
MultiLocation
,
context
:
InteriorMultiLocation
,
)
->
Result
<
(),
()
>
{
self
.0
.iter_mut
()
.try_for_each
(|
i
|
i
.reanchor
(
target
,
context
))
self
.0
.iter_mut
()
.try_for_each
(|
i
|
i
.reanchor
(
target
,
context
))
?
;
self
.0
.sort
();
Ok
(())
}
/// Return a reference to an item at a specific index or `None` if it doesn't exist.
...
...
@@ -985,6 +989,42 @@ mod tests {
assert!
(
r
.is_err
());
}
#[test]
fn
reanchor_preserves_sorting
()
{
use
super
::
*
;
use
alloc
::
vec
;
let
reanchor_context
=
X1
(
Parachain
(
2000
));
let
dest
=
MultiLocation
::
new
(
1
,
Here
);
let
asset_1
:
MultiAsset
=
(
MultiLocation
::
new
(
0
,
X2
(
PalletInstance
(
50
),
GeneralIndex
(
1
))),
10
)
.into
();
let
mut
asset_1_reanchored
=
asset_1
.clone
();
assert!
(
asset_1_reanchored
.reanchor
(
&
dest
,
reanchor_context
)
.is_ok
());
assert_eq!
(
asset_1_reanchored
,
(
MultiLocation
::
new
(
0
,
X3
(
Parachain
(
2000
),
PalletInstance
(
50
),
GeneralIndex
(
1
))),
10
)
.into
()
);
let
asset_2
:
MultiAsset
=
(
MultiLocation
::
new
(
1
,
Here
),
10
)
.into
();
let
mut
asset_2_reanchored
=
asset_2
.clone
();
assert!
(
asset_2_reanchored
.reanchor
(
&
dest
,
reanchor_context
)
.is_ok
());
assert_eq!
(
asset_2_reanchored
,
(
MultiLocation
::
new
(
0
,
Here
),
10
)
.into
());
let
asset_3
:
MultiAsset
=
(
MultiLocation
::
new
(
1
,
X1
(
Parachain
(
1000
))),
10
)
.into
();
let
mut
asset_3_reanchored
=
asset_3
.clone
();
assert!
(
asset_3_reanchored
.reanchor
(
&
dest
,
reanchor_context
)
.is_ok
());
assert_eq!
(
asset_3_reanchored
,
(
MultiLocation
::
new
(
0
,
X1
(
Parachain
(
1000
))),
10
)
.into
());
let
mut
assets
:
MultiAssets
=
vec!
[
asset_1
.clone
(),
asset_2
.clone
(),
asset_3
.clone
()]
.into
();
assert_eq!
(
assets
.clone
(),
vec!
[
asset_1
.clone
(),
asset_2
.clone
(),
asset_3
.clone
()]
.into
());
assert!
(
assets
.reanchor
(
&
dest
,
reanchor_context
)
.is_ok
());
assert_eq!
(
assets
,
vec!
[
asset_2_reanchored
,
asset_3_reanchored
,
asset_1_reanchored
]
.into
());
}
#[test]
fn
decoding_respects_limit
()
{
use
super
::
*
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment