git.delta.rocks / unique-network / refs/commits / 05c886f6b558

difftreelog

fix take parents:0 multilocations into account

Daniel Shiposha2023-11-16parent: #046e9b6.patch.diff
in: master

1 file changed

modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
246 /// * It is `../Parachain(<Unique Network Para ID>)/GeneralIndex(<Collection ID>)` that corresponds246 /// * It is `../Parachain(<Unique Network Para ID>)/GeneralIndex(<Collection ID>)` that corresponds
247 /// to the collection with the ID equal to `<Collection ID>`. The `<Collection ID>` must be in the valid range,247 /// to the collection with the ID equal to `<Collection ID>`. The `<Collection ID>` must be in the valid range,
248 /// otherwise `None` is returned.248 /// otherwise `None` is returned.
249 /// * It is `GeneralIndex(<Collection ID>)`. Same as the last one above.
249 ///250 ///
250 /// If the multilocation doesn't match the patterns listed above,251 /// If the multilocation doesn't match the patterns listed above,
251 /// or the `<Collection ID>` points to a foreign collection,252 /// or the `<Collection ID>` points to a foreign collection,
257258
258 let self_location = T::SelfLocation::get();259 let self_location = T::SelfLocation::get();
259260
260 if *asset_location == Here.into() || *asset_location == self_location {261 if *asset_location == Here.into() || *asset_location == self_location {
262 return Some(CollectionLocality::Local(NATIVE_FUNGIBLE_COLLECTION_ID));
263 }
264
265 let collection_junction = if asset_location.parents == 0 {
266 match &asset_location.interior {
267 X1(junction) => junction,
268 _ => return None,
269 }
270 } else if asset_location.parents == self_location.parents {
271 asset_location
272 .interior
273 .match_and_split(&self_location.interior)?
274 } else {
275 return None;
276 };
277
261 Some(CollectionLocality::Local(NATIVE_FUNGIBLE_COLLECTION_ID))278 let GeneralIndex(collection_id) = collection_junction else {
262 } else if asset_location.parents == self_location.parents {279 return None;
263 match asset_location280 };
264 .interior281
265 .match_and_split(&self_location.interior)
266 {
267 Some(GeneralIndex(collection_id)) => {
268 let collection_id = CollectionId((*collection_id).try_into().ok()?);282 let collection_id = CollectionId((*collection_id).try_into().ok()?);
269283
270 Self::collection_to_foreign_asset(collection_id)284 Self::collection_to_foreign_asset(collection_id)
271 .is_none()285 .is_none()
272 .then_some(CollectionLocality::Local(collection_id))286 .then_some(CollectionLocality::Local(collection_id))
273 }
274 _ => None,
275 }
276 } else {
277 None
278 }
279 }287 }
280288
281 /// Converts an asset ID to a Unique Network's collection locality (either foreign or a local one).289 /// Converts an asset ID to a Unique Network's collection locality (either foreign or a local one).