git.delta.rocks / unique-network / refs/commits / e2da42b8b024

difftreelog

feat xcm nft support

Daniel Shiposha2023-10-18parent: #5bde44b.patch.diff
in: master

5 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2351,6 +2351,11 @@
 	/// Is the collection a foreign one?
 	fn is_foreign(&self) -> bool;
 
+	/// Does the token have children?
+	fn token_has_children(&self, _token: TokenId) -> bool {
+		false
+	}
+
 	/// Create a collection's item using a transaction.
 	///
 	/// This function performs additional XCM-related checks before the actual creation.
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
364364
365 fn check_out(_dest: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}365 fn check_out(_dest: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}
366366
367 fn deposit_asset(what: &MultiAsset, to: &MultiLocation, context: &XcmContext) -> XcmResult {367 fn deposit_asset(what: &MultiAsset, to: &MultiLocation, _context: &XcmContext) -> XcmResult {
368 let collection_id = Self::multiasset_to_collection(what)?;368 let collection_id = Self::multiasset_to_collection(what)?;
369 let dispatch =369 let dispatch =
370 T::CollectionDispatch::dispatch(collection_id).map_err(|_| XcmError::AssetNotFound)?;370 T::CollectionDispatch::dispatch(collection_id).map_err(|_| XcmError::AssetNotFound)?;
397 from: &MultiLocation,397 from: &MultiLocation,
398 _maybe_context: Option<&XcmContext>,398 _maybe_context: Option<&XcmContext>,
399 ) -> Result<staging_xcm_executor::Assets, XcmError> {399 ) -> Result<staging_xcm_executor::Assets, XcmError> {
400 let from = T::LocationToAccountId::convert_location(from)
401 .ok_or(XcmExecutorError::AccountIdConversionFailed)?;
402
403 let collection_id = Self::multiasset_to_collection(what)?;
404 let dispatch =
405 T::CollectionDispatch::dispatch(collection_id).map_err(|_| XcmError::AssetNotFound)?;
406
407 let collection = dispatch.as_dyn();
408 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;
409
410 match what.fun {
411 Fungibility::Fungible(amount) => xcm_ext
412 .burn_item(from, TokenId::default(), amount)
413 .map_err(|_| XcmError::FailedToTransactAsset("fungible item withdraw failed"))?,
414
415 Fungibility::NonFungible(asset_instance) => {
416 let token_id =
417 Self::asset_instance_to_token_id(xcm_ext, collection_id, &asset_instance)?
418 .ok_or(XcmError::AssetNotFound)?;
419
420 if xcm_ext.token_has_children(token_id) {
400 Err(XcmError::Unimplemented)421 return Err(XcmError::Unimplemented);
422 }
423
424 let depositor = &from;
425 let to = Self::pallet_account();
426 let amount = 1;
427 xcm_ext
428 .transfer_item(depositor, &from, &to, token_id, amount, &ZeroBudget)
429 .map_err(|_| {
430 XcmError::FailedToTransactAsset("nonfungible item withdraw failed")
431 })?;
432 }
433 }
434
435 Ok(what.clone().into())
401 }436 }
402437
403 fn internal_transfer_asset(438 fn internal_transfer_asset(
406 to: &MultiLocation,441 to: &MultiLocation,
407 _context: &XcmContext,442 _context: &XcmContext,
408 ) -> Result<staging_xcm_executor::Assets, XcmError> {443 ) -> Result<staging_xcm_executor::Assets, XcmError> {
444 let collection_id = Self::multiasset_to_collection(what)?;
445
446 let dispatch =
447 T::CollectionDispatch::dispatch(collection_id).map_err(|_| XcmError::AssetNotFound)?;
448 let collection = dispatch.as_dyn();
409 Err(XcmError::Unimplemented)449 let xcm_ext = collection.xcm_extensions().ok_or(XcmError::NoPermission)?;
450
451 let from = T::LocationToAccountId::convert_location(from)
452 .ok_or(XcmExecutorError::AccountIdConversionFailed)?;
453
454 let to = T::LocationToAccountId::convert_location(to)
455 .ok_or(XcmExecutorError::AccountIdConversionFailed)?;
456
457 let depositor = &from;
458
459 match what.fun {
460 Fungibility::Fungible(amount) => xcm_ext
461 .transfer_item(
462 depositor,
463 &from,
464 &to,
465 TokenId::default(),
466 amount,
467 &ZeroBudget,
468 )
469 .map_err(|_| XcmError::FailedToTransactAsset("fungible item transfer failed"))?,
470
471 Fungibility::NonFungible(asset_instance) => {
472 let token_id =
473 Self::asset_instance_to_token_id(xcm_ext, collection_id, &asset_instance)?
474 .ok_or(XcmError::AssetNotFound)?;
475
476 let amount = 1;
477
478 xcm_ext
479 .transfer_item(depositor, &from, &to, token_id, amount, &ZeroBudget)
480 .map_err(|_| {
481 XcmError::FailedToTransactAsset("nonfungible item transfer failed")
482 })?;
483 }
484 }
485
486 Ok(what.clone().into())
410 }487 }
411}488}
412489
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -95,9 +95,8 @@
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
 use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
 use up_data_structs::{
-	budget::{Budget, ZeroBudget},
-	mapping::TokenAddressMapping,
-	AccessMode, CollectionId, CreateCollectionData, Property, PropertyKey, TokenId,
+	budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId, Property, PropertyKey,
+	TokenId,
 };
 use weights::WeightInfo;
 
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -576,6 +576,10 @@
 		self.flags.foreign
 	}
 
+	fn token_has_children(&self, token: TokenId) -> bool {
+		<Pallet<T>>::token_has_children(self.id, token)
+	}
+
 	fn create_item_internal(
 		&self,
 		depositor: &<T>::CrossAccountId,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -117,8 +117,8 @@
 use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
 use up_data_structs::{
 	budget::Budget, mapping::TokenAddressMapping, AccessMode, AuxPropertyValue, CollectionId,
-	CreateCollectionData, CreateNftExData, CustomDataLimit, PropertiesPermissionMap, Property,
-	PropertyKey, PropertyKeyPermission, PropertyScope, PropertyValue, TokenChild, TokenId,
+	CreateNftExData, CustomDataLimit, PropertiesPermissionMap, Property, PropertyKey,
+	PropertyKeyPermission, PropertyScope, PropertyValue, TokenChild, TokenId,
 	TokenProperties as TokenPropertiesT,
 };
 use weights::WeightInfo;