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
2351 /// Is the collection a foreign one?2351 /// Is the collection a foreign one?
2352 fn is_foreign(&self) -> bool;2352 fn is_foreign(&self) -> bool;
2353
2354 /// Does the token have children?
2355 fn token_has_children(&self, _token: TokenId) -> bool {
2356 false
2357 }
23532358
2354 /// Create a collection's item using a transaction.2359 /// Create a collection's item using a transaction.
2355 ///2360 ///
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
95use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};95use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
96use sp_std::{collections::btree_map::BTreeMap, vec::Vec};96use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
97use up_data_structs::{97use up_data_structs::{
98 budget::{Budget, ZeroBudget},98 budget::Budget, mapping::TokenAddressMapping, AccessMode, CollectionId, Property, PropertyKey,
99 mapping::TokenAddressMapping,
100 AccessMode, CollectionId, CreateCollectionData, Property, PropertyKey, TokenId,99 TokenId,
101};100};
102use weights::WeightInfo;101use weights::WeightInfo;
103102
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
576 self.flags.foreign576 self.flags.foreign
577 }577 }
578
579 fn token_has_children(&self, token: TokenId) -> bool {
580 <Pallet<T>>::token_has_children(self.id, token)
581 }
578582
579 fn create_item_internal(583 fn create_item_internal(
580 &self,584 &self,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
117use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};117use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec};
118use up_data_structs::{118use up_data_structs::{
119 budget::Budget, mapping::TokenAddressMapping, AccessMode, AuxPropertyValue, CollectionId,119 budget::Budget, mapping::TokenAddressMapping, AccessMode, AuxPropertyValue, CollectionId,
120 CreateCollectionData, CreateNftExData, CustomDataLimit, PropertiesPermissionMap, Property,120 CreateNftExData, CustomDataLimit, PropertiesPermissionMap, Property, PropertyKey,
121 PropertyKey, PropertyKeyPermission, PropertyScope, PropertyValue, TokenChild, TokenId,121 PropertyKeyPermission, PropertyScope, PropertyValue, TokenChild, TokenId,
122 TokenProperties as TokenPropertiesT,122 TokenProperties as TokenPropertiesT,
123};123};