From e8a0ca9c8105a538e71ca73672f53dba2eff34df Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 23 Oct 2023 19:45:21 +0200 Subject: [PATCH] fix: rfts are unsupported in XCM --- pallets/foreign-assets/src/benchmarking.rs | 11 +++++---- pallets/foreign-assets/src/lib.rs | 28 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pallets/foreign-assets/src/benchmarking.rs b/pallets/foreign-assets/src/benchmarking.rs index 4df83da919..f3ce15a643 100644 --- a/pallets/foreign-assets/src/benchmarking.rs +++ b/pallets/foreign-assets/src/benchmarking.rs @@ -18,12 +18,12 @@ use frame_benchmarking::v2::*; use frame_system::RawOrigin; -use pallet_common::benchmarking::create_u16_data; +use pallet_common::benchmarking::{create_data, create_u16_data}; use sp_std::vec; use staging_xcm::prelude::*; -use up_data_structs::{CollectionMode, MAX_COLLECTION_NAME_LENGTH}; +use up_data_structs::{MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH}; -use super::{Call, Config, Pallet}; +use super::{Call, Config, ForeignCollectionMode, Pallet}; #[benchmarks] mod benchmarks { @@ -35,10 +35,11 @@ mod benchmarks { let location = MultiLocation::from(X3(Parachain(1000), PalletInstance(42), GeneralIndex(1))); let name = create_u16_data::(); - let mode = CollectionMode::NFT; + let token_prefix = create_data::(); + let mode = ForeignCollectionMode::NFT; #[extrinsic_call] - _(RawOrigin::Root, location, name, mode); + _(RawOrigin::Root, location, name, token_prefix, mode); Ok(()) } diff --git a/pallets/foreign-assets/src/lib.rs b/pallets/foreign-assets/src/lib.rs index a9d2632bd1..fd8531eea1 100644 --- a/pallets/foreign-assets/src/lib.rs +++ b/pallets/foreign-assets/src/lib.rs @@ -39,8 +39,9 @@ use staging_xcm_executor::{ Assets, }; use up_data_structs::{ - budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CreateCollectionData, - CreateFungibleData, CreateItemData, CreateNftData, Property, PropertyKey, TokenId, + budget::ZeroBudget, CollectionId, CollectionMode, CollectionName, CollectionTokenPrefix, + CreateCollectionData, CreateFungibleData, CreateItemData, CreateNftData, Property, PropertyKey, + TokenId, }; pub mod weights; @@ -87,7 +88,7 @@ pub mod module { #[pallet::error] pub enum Error { - /// The foreign asset is already registered + /// The foreign asset is already registered. ForeignAssetAlreadyRegistered, } @@ -136,7 +137,8 @@ pub mod module { origin: OriginFor, reserve_location: MultiLocation, name: CollectionName, - mode: CollectionMode, + token_prefix: CollectionTokenPrefix, + mode: ForeignCollectionMode, ) -> DispatchResult { T::ForceRegisterOrigin::ensure_origin(origin.clone())?; @@ -160,8 +162,9 @@ pub mod module { is_special_collection, CreateCollectionData { name, + token_prefix, description, - mode, + mode: mode.into(), properties: vec![Property { key: Self::reserve_location_property_key(), @@ -560,6 +563,21 @@ pub use frame_support::{ weights::{WeightToFee, WeightToFeePolynomial}, }; +#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)] +pub enum ForeignCollectionMode { + NFT, + Fungible(u8), +} + +impl Into for ForeignCollectionMode { + fn into(self) -> CollectionMode { + match self { + Self::NFT => CollectionMode::NFT, + Self::Fungible(decimals) => CollectionMode::Fungible(decimals), + } + } +} + pub struct FreeForAll; impl WeightTrader for FreeForAll {