git.delta.rocks / unique-network / refs/commits / 644dfbebda26

difftreelog

fix correct xcm executor errors, remove use of props

Daniel Shiposha2023-11-24parent: #9d0fd83.patch.diff
in: master

1 file changed

modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
42};42};
43use up_data_structs::{43use up_data_structs::{
44 budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CollectionTokenPrefix,44 budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CollectionTokenPrefix,
45 CreateCollectionData, CreateFungibleData, CreateItemData, CreateNftData, Property, PropertyKey,45 CreateCollectionData, CreateFungibleData, CreateItemData, TokenId,
46 TokenId,
47};46};
4847
57#[frame_support::pallet]56#[frame_support::pallet]
58pub mod module {57pub mod module {
59 use pallet_common::CollectionIssuer;58 use pallet_common::CollectionIssuer;
60 use up_data_structs::{59 use up_data_structs::CollectionDescription;
61 CollectionDescription, Property, PropertyKeyPermission, PropertyPermission,
62 };
6360
64 use super::*;61 use super::*;
6562
179 description,176 description,
180 mode: mode.into(),177 mode: mode.into(),
181
182 properties: vec![Property {
183 key: Self::reserve_location_property_key(),
184 value: asset_id
185 .encode()
186 .try_into()
187 .expect("multilocation is less than 32k; qed"),
188 }]
189 .try_into()
190 .expect("just one property can always be stored; qed"),
191
192 token_property_permissions: vec![PropertyKeyPermission {
193 key: Self::reserve_asset_instance_property_key(),
194 permission: PropertyPermission {
195 mutable: false,
196 collection_admin: true,
197 token_owner: false,
198 },
199 }]
200 .try_into()
201 .expect("just one property permission can always be stored; qed"),
202 ..Default::default()178 ..Default::default()
203 },179 },
204 )?;180 )?;
222 T::CrossAccountId::from_sub(owner)198 T::CrossAccountId::from_sub(owner)
223 }199 }
224
225 fn reserve_location_property_key() -> PropertyKey {
226 b"reserve-location"
227 .to_vec()
228 .try_into()
229 .expect("key length < max property key length; qed")
230 }
231
232 fn reserve_asset_instance_property_key() -> PropertyKey {
233 b"reserve-asset-instance"
234 .to_vec()
235 .try_into()
236 .expect("key length < max property key length; qed")
237 }
238200
239 /// Converts a concrete asset ID (the asset multilocation) to a local collection on Unique Network.201 /// Converts a concrete asset ID (the asset multilocation) to a local collection on Unique Network.
240 ///202 ///
331 asset_instance: &AssetInstance,293 asset_instance: &AssetInstance,
332 to: T::CrossAccountId,294 to: T::CrossAccountId,
333 ) -> DispatchResult {295 ) -> DispatchResult {
334 let asset_instance_encoded = asset_instance.encode();
335
336 let derivative_token_id = xcm_ext.create_item(296 let derivative_token_id = xcm_ext.create_item(
337 &Self::pallet_account(),297 &Self::pallet_account(),
338 to,298 to,
339 CreateItemData::NFT(CreateNftData {299 CreateItemData::NFT(Default::default()),
340 properties: vec![Property {
341 key: Self::reserve_asset_instance_property_key(),
342 value: asset_instance_encoded
343 .try_into()
344 .expect("asset instance length <= 32 bytes which is less than value length limit; qed"),
345 }]
346 .try_into()
347 .expect("just one property can always be stored; qed"),
348 }),
349 &ZeroBudget,300 &ZeroBudget,
350 )?;301 )?;
351302
388 Self::create_foreign_asset_instance(xcm_ext, collection_id, asset_instance, to)339 Self::create_foreign_asset_instance(xcm_ext, collection_id, asset_instance, to)
389 }340 }
390 (CollectionLocality::Local(_), None) => {341 (CollectionLocality::Local(_), None) => {
391 return Err(XcmError::AssetNotFound);342 return Err(XcmExecutorError::InstanceConversionFailed.into());
392 }343 }
393 };344 };
394345
406 from: T::CrossAccountId,357 from: T::CrossAccountId,
407 ) -> XcmResult {358 ) -> XcmResult {
408 let token_id = Self::asset_instance_to_token_id(collection_locality, asset_instance)359 let token_id = Self::asset_instance_to_token_id(collection_locality, asset_instance)
409 .ok_or(XcmError::AssetNotFound)?;360 .ok_or(XcmExecutorError::InstanceConversionFailed)?;
410361
411 let depositor = &from;362 let depositor = &from;
412 let to = Self::pallet_account();363 let to = Self::pallet_account();
450401
451 let collection_locality = Self::asset_to_collection(&what.id)?;402 let collection_locality = Self::asset_to_collection(&what.id)?;
452 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)403 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)
453 .map_err(|_| XcmError::AssetNotFound)?;404 .map_err(|_| XcmExecutorError::AssetIdConversionFailed)?;
454405
455 let collection = dispatch.as_dyn();406 let collection = dispatch.as_dyn();
456 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::Unimplemented)?;407 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::Unimplemented)?;
482433
483 let collection_locality = Self::asset_to_collection(&what.id)?;434 let collection_locality = Self::asset_to_collection(&what.id)?;
484 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)435 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)
485 .map_err(|_| XcmError::AssetNotFound)?;436 .map_err(|_| XcmExecutorError::AssetIdConversionFailed)?;
486437
487 let collection = dispatch.as_dyn();438 let collection = dispatch.as_dyn();
488 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;439 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;
515 let collection_locality = Self::asset_to_collection(&what.id)?;466 let collection_locality = Self::asset_to_collection(&what.id)?;
516467
517 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)468 let dispatch = T::CollectionDispatch::dispatch(*collection_locality)
518 .map_err(|_| XcmError::AssetNotFound)?;469 .map_err(|_| XcmExecutorError::AssetIdConversionFailed)?;
519 let collection = dispatch.as_dyn();470 let collection = dispatch.as_dyn();
520 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;471 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;
521472
534485
535 Fungibility::NonFungible(asset_instance) => {486 Fungibility::NonFungible(asset_instance) => {
536 token_id = Self::asset_instance_to_token_id(collection_locality, &asset_instance)487 token_id = Self::asset_instance_to_token_id(collection_locality, &asset_instance)
537 .ok_or(XcmError::AssetNotFound)?;488 .ok_or(XcmExecutorError::InstanceConversionFailed)?;
538489
539 amount = 1;490 amount = 1;
540 map_error = |_| XcmError::FailedToTransactAsset("non-fungible item transfer failed")491 map_error = |_| XcmError::FailedToTransactAsset("non-fungible item transfer failed")