From 05c886f6b558cd5c59f75b9424c7c9214d32890b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 16 Nov 2023 12:51:12 +0000 Subject: [PATCH] fix: take parents:0 multilocations into account --- --- a/pallets/foreign-assets/src/lib.rs +++ b/pallets/foreign-assets/src/lib.rs @@ -246,6 +246,7 @@ /// * It is `../Parachain()/GeneralIndex()` that corresponds /// to the collection with the ID equal to ``. The `` must be in the valid range, /// otherwise `None` is returned. + /// * It is `GeneralIndex()`. Same as the last one above. /// /// If the multilocation doesn't match the patterns listed above, /// or the `` points to a foreign collection, @@ -258,24 +259,31 @@ let self_location = T::SelfLocation::get(); if *asset_location == Here.into() || *asset_location == self_location { - Some(CollectionLocality::Local(NATIVE_FUNGIBLE_COLLECTION_ID)) + return Some(CollectionLocality::Local(NATIVE_FUNGIBLE_COLLECTION_ID)); + } + + let collection_junction = if asset_location.parents == 0 { + match &asset_location.interior { + X1(junction) => junction, + _ => return None, + } } else if asset_location.parents == self_location.parents { - match asset_location + asset_location .interior - .match_and_split(&self_location.interior) - { - Some(GeneralIndex(collection_id)) => { - let collection_id = CollectionId((*collection_id).try_into().ok()?); + .match_and_split(&self_location.interior)? + } else { + return None; + }; + + let GeneralIndex(collection_id) = collection_junction else { + return None; + }; - Self::collection_to_foreign_asset(collection_id) - .is_none() - .then_some(CollectionLocality::Local(collection_id)) - } - _ => None, - } - } else { - None - } + let collection_id = CollectionId((*collection_id).try_into().ok()?); + + Self::collection_to_foreign_asset(collection_id) + .is_none() + .then_some(CollectionLocality::Local(collection_id)) } /// Converts an asset ID to a Unique Network's collection locality (either foreign or a local one). -- gitstuff