Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatting
  • Loading branch information
gavofyork committed Dec 6, 2021
commit db7cd5fce3834d69e28d76d435dddaf02b058470
6 changes: 5 additions & 1 deletion xcm/src/v1/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ impl MultiAsset {

/// 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 `ancestry`.
pub fn reanchored(mut self, target: &MultiLocation, ancestry: &MultiLocation) -> Result<Self, ()> {
pub fn reanchored(
mut self,
target: &MultiLocation,
ancestry: &MultiLocation,
) -> Result<Self, ()> {
self.id.reanchor(target, ancestry)?;
Ok(self)
}
Expand Down
24 changes: 13 additions & 11 deletions xcm/src/v1/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ impl MultiLocation {
/// The context of `self` is provided as `ancestry`.
///
/// Does not modify `self` in case of overflow.
pub fn reanchor(
&mut self,
target: &MultiLocation,
ancestry: &MultiLocation,
) -> Result<(), ()> {
pub fn reanchor(&mut self, target: &MultiLocation, ancestry: &MultiLocation) -> Result<(), ()> {
// TODO: Optimize this.

// 1. Use our `ancestry` to figure out how the `target` would address us.
Expand Down Expand Up @@ -845,7 +841,8 @@ mod tests {

#[test]
fn simplify_basic_works() {
let mut location: MultiLocation = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let mut location: MultiLocation =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let context = X2(Parachain(1000), PalletInstance(42));
let expected = GeneralIndex(69).into();
location.simplify(&context);
Expand All @@ -863,7 +860,8 @@ mod tests {
location.simplify(&context);
assert_eq!(location, expected);

let mut location: MultiLocation = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let mut location: MultiLocation =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let context = X3(OnlyChild, Parachain(1000), PalletInstance(42));
let expected = GeneralIndex(69).into();
location.simplify(&context);
Expand All @@ -872,15 +870,19 @@ mod tests {

#[test]
fn simplify_incompatible_location_fails() {
let mut location: MultiLocation = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let mut location: MultiLocation =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let context = X3(Parachain(1000), PalletInstance(42), GeneralIndex(42));
let expected = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let expected =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
location.simplify(&context);
assert_eq!(location, expected);

let mut location: MultiLocation = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let mut location: MultiLocation =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let context = X1(Parachain(1000));
let expected = (Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
let expected =
(Parent, Parent, Parachain(1000), PalletInstance(42), GeneralIndex(69)).into();
location.simplify(&context);
assert_eq!(location, expected);
}
Expand Down