diff --git a/pallets/nfts/src/benchmarking.rs b/pallets/nfts/src/benchmarking.rs index efbebae2..75871e41 100644 --- a/pallets/nfts/src/benchmarking.rs +++ b/pallets/nfts/src/benchmarking.rs @@ -42,6 +42,7 @@ fn create_collection, I: 'static>( T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); assert_ok!(Nfts::::force_create( SystemOrigin::Root.into(), + collection.clone(), caller_lookup.clone(), default_collection_config::() )); @@ -230,19 +231,14 @@ benchmarks_instance_pallet! { whitelist_account!(caller); let admin = T::Lookup::unlookup(caller.clone()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - let call = Call::::create { admin, config: default_collection_config::() }; + let call = Call::::create { admin, collection, config: default_collection_config::() }; }: { call.dispatch_bypass_filter(origin)? } - verify { - assert_last_event::(Event::NextCollectionIdIncremented { next_id: Some(T::Helper::collection(1)) }.into()); - } force_create { + let collection = T::Helper::collection(0); let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - }: _(SystemOrigin::Root, caller_lookup, default_collection_config::()) - verify { - assert_last_event::(Event::NextCollectionIdIncremented { next_id: Some(T::Helper::collection(1)) }.into()); - } + }: _(SystemOrigin::Root, collection, caller_lookup, default_collection_config::()) destroy { let m in 0 .. 1_000; @@ -881,6 +877,7 @@ benchmarks_instance_pallet! { let item = T::Helper::item(0); assert_ok!(Nfts::::force_create( SystemOrigin::Root.into(), + collection.clone(), caller_lookup.clone(), default_collection_config::() )); diff --git a/pallets/nfts/src/common_functions.rs b/pallets/nfts/src/common_functions.rs index 273a810f..18cd5c6d 100644 --- a/pallets/nfts/src/common_functions.rs +++ b/pallets/nfts/src/common_functions.rs @@ -85,23 +85,4 @@ impl, I: 'static> Pallet { Ok(()) } - - pub(crate) fn set_next_collection_id(collection: T::CollectionId) { - let next_id = collection.increment(); - NextCollectionId::::set(next_id.clone()); - Self::deposit_event(Event::NextCollectionIdIncremented { next_id }); - } - - #[allow(missing_docs)] - #[cfg(any(test, feature = "runtime-benchmarks"))] - pub fn set_next_id(id: T::CollectionId) { - NextCollectionId::::set(Some(id)); - } - - #[cfg(test)] - pub fn get_next_id() -> T::CollectionId { - NextCollectionId::::get() - .or(T::CollectionId::initial_value()) - .expect("Failed to get next collection ID") - } } diff --git a/pallets/nfts/src/impl_nonfungibles.rs b/pallets/nfts/src/impl_nonfungibles.rs index 4c73d141..124f5bb3 100644 --- a/pallets/nfts/src/impl_nonfungibles.rs +++ b/pallets/nfts/src/impl_nonfungibles.rs @@ -151,36 +151,11 @@ impl, I: 'static> Create<::AccountId, Collection { /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. fn create_collection( - who: &T::AccountId, - admin: &T::AccountId, - config: &CollectionConfigFor, + _who: &T::AccountId, + _admin: &T::AccountId, + _config: &CollectionConfigFor, ) -> Result { - // DepositRequired can be disabled by calling the force_create() only - ensure!( - !config.has_disabled_setting(CollectionSetting::DepositRequired), - Error::::WrongSetting - ); - - let collection = NextCollectionId::::get() - .or(T::CollectionId::initial_value()) - .ok_or(Error::::UnknownCollection)?; - - Self::do_create_collection( - collection.clone(), - who.clone(), - admin.clone(), - config.clone(), - T::CollectionDeposit::get(), - Event::Created { - collection: collection.clone(), - creator: who.clone(), - owner: admin.clone(), - }, - )?; - - Self::set_next_collection_id(collection.clone()); - - Ok(collection) + unimplemented!("This function can be used with XCM location."); } /// Create a collection of nonfungible items with `collection` Id to be owned by `who` and diff --git a/pallets/nfts/src/lib.rs b/pallets/nfts/src/lib.rs index 04b73fa6..362c541c 100644 --- a/pallets/nfts/src/lib.rs +++ b/pallets/nfts/src/lib.rs @@ -57,8 +57,7 @@ use core::cmp::Ordering; use codec::{Decode, Encode}; use frame_support::traits::{ - tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, Incrementable, - ReservableCurrency, + tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency, }; use frame_system::Config as SystemConfig; pub use pallet::*; @@ -140,15 +139,7 @@ pub mod pallet { + IsType<::RuntimeEvent>; /// Identifier for the collection of item. - /// - /// SAFETY: The functions in the `Incrementable` trait are fallible. If the functions - /// of the implementation both return `None`, the automatic CollectionId generation - /// should not be used. So the `create` and `force_create` extrinsics and the - /// `create_collection` function will return an `UnknownCollection` Error. Instead use - /// the `create_collection_with_id` function. However, if the `Incrementable` trait - /// implementation has an incremental order, the `create_collection_with_id` function - /// should not be used as it can claim a value in the ID sequence. - type CollectionId: Member + Parameter + MaxEncodedLen + Clone + Incrementable; + type CollectionId: Member + Parameter + MaxEncodedLen + Clone; /// The type used to identify a unique item within a collection. type ItemId: Member + Parameter + MaxEncodedLen + Copy; @@ -569,8 +560,6 @@ pub mod pallet { CollectionMaxSupplySet { collection: T::CollectionId, max_supply: u32 }, /// Mint settings for a collection had changed. CollectionMintSettingsUpdated { collection: T::CollectionId }, - /// Event gets emitted when the `NextCollectionId` gets incremented. - NextCollectionIdIncremented { next_id: Option }, /// The price was set for the item. ItemPriceSet { collection: T::CollectionId, @@ -774,13 +763,10 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, + collection: T::CollectionId, admin: AccountIdLookupOf, config: CollectionConfigFor, ) -> DispatchResult { - let collection = NextCollectionId::::get() - .or(T::CollectionId::initial_value()) - .ok_or(Error::::UnknownCollection)?; - let owner = T::CreateOrigin::ensure_origin(origin, &collection)?; let admin = T::Lookup::lookup(admin)?; @@ -799,7 +785,6 @@ pub mod pallet { Event::Created { collection: collection.clone(), creator: owner, owner: admin }, )?; - Self::set_next_collection_id(collection); Ok(()) } @@ -822,26 +807,22 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, + collection: T::CollectionId, owner: AccountIdLookupOf, config: CollectionConfigFor, ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; let owner = T::Lookup::lookup(owner)?; - let collection = NextCollectionId::::get() - .or(T::CollectionId::initial_value()) - .ok_or(Error::::UnknownCollection)?; - Self::do_create_collection( collection.clone(), owner.clone(), owner.clone(), config, Zero::zero(), - Event::ForceCreated { collection: collection.clone(), owner }, + Event::ForceCreated { collection, owner }, )?; - Self::set_next_collection_id(collection); Ok(()) } diff --git a/pallets/nfts/src/tests.rs b/pallets/nfts/src/tests.rs index 27e0aa90..48d6ebd0 100644 --- a/pallets/nfts/src/tests.rs +++ b/pallets/nfts/src/tests.rs @@ -167,6 +167,7 @@ fn basic_minting_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id_1.clone(), owner_1.clone(), default_collection_config() )); @@ -183,6 +184,7 @@ fn basic_minting_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id_2.clone(), owner_2.clone(), default_collection_config() )); @@ -218,6 +220,7 @@ fn lifecycle_should_work() { Balances::make_free_balance_be(&account(2), 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(owner.clone()), + collection_id.clone(), owner.clone(), collection_config_with_all_settings_enabled() )); @@ -349,6 +352,7 @@ fn destroy_with_bad_witness_should_not_work() { Balances::make_free_balance_be(&account(1), 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(account(1)), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -378,6 +382,7 @@ fn destroy_should_work() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(collection_owner.clone()), + collection_id.clone(), collection_owner.clone(), collection_config_with_all_settings_enabled() )); @@ -444,6 +449,7 @@ fn mint_should_work() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -520,6 +526,7 @@ fn mint_should_work() { // validate types assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 1, account(1), default_collection_config() )); @@ -580,6 +587,7 @@ fn transfer_should_work() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -613,6 +621,7 @@ fn transfer_should_work() { let collection_id = 1; assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, account(1), collection_config_from_disabled_settings( CollectionSetting::TransferableItems | CollectionSetting::DepositRequired @@ -639,6 +648,7 @@ fn locking_transfer_should_work() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -674,6 +684,7 @@ fn origin_guards_should_work() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -728,6 +739,7 @@ fn transfer_owner_should_work() { Balances::make_free_balance_be(&account(3), 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(account(1)), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -792,6 +804,7 @@ fn set_team_should_work() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config(), )); @@ -867,6 +880,7 @@ fn set_collection_metadata_should_work() { ); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -956,6 +970,7 @@ fn set_item_metadata_should_work() { // Cannot add metadata to unknown item assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1026,6 +1041,7 @@ fn set_collection_owner_attributes_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1116,6 +1132,7 @@ fn set_collection_system_attributes_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1198,6 +1215,7 @@ fn set_item_owner_attributes_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1382,6 +1400,7 @@ fn set_external_account_attributes_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1470,6 +1489,7 @@ fn validate_deposit_required_setting() { // attributes for free. assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -1555,6 +1575,7 @@ fn set_attribute_should_respect_lock() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled(), )); @@ -1660,6 +1681,7 @@ fn preserve_config_for_frozen_items() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1716,6 +1738,7 @@ fn force_update_collection_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_with_all_settings_enabled() )); @@ -1839,6 +1862,7 @@ fn burn_works() { Balances::make_free_balance_be(&collection_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, collection_owner.clone(), collection_config_with_all_settings_enabled() )); @@ -1889,6 +1913,7 @@ fn approval_lifecycle_works() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -1926,6 +1951,7 @@ fn approval_lifecycle_works() { let collection_id = 1; assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, account(1), collection_config_from_disabled_settings( CollectionSetting::TransferableItems | CollectionSetting::DepositRequired @@ -1965,6 +1991,7 @@ fn check_approval_without_deadline_works() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, collection_owner.clone(), default_collection_config() )); @@ -2014,6 +2041,7 @@ fn check_approval_with_deadline_works() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, collection_owner.clone(), default_collection_config() )); @@ -2087,6 +2115,7 @@ fn cancel_approval_works() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -2169,6 +2198,7 @@ fn cancel_collection_approval_works() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, collection_owner.clone(), default_collection_config() )); @@ -2235,6 +2265,7 @@ fn force_cancel_collection_approvals_work() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, collection_owner.clone(), default_collection_config() )); @@ -2296,6 +2327,7 @@ fn approving_multiple_accounts_works() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -2352,6 +2384,7 @@ fn approvals_limit_works() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -2393,11 +2426,13 @@ fn approve_collection_transfer_works() { Balances::make_free_balance_be(&delegate, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection, collection_owner.clone(), default_collection_config() )); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + locked_collection, collection_owner.clone(), default_collection_config() )); @@ -2517,11 +2552,13 @@ fn force_approve_collection_transfer_works() { Balances::make_free_balance_be(&delegate, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection, collection_owner.clone(), default_collection_config() )); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + locked_collection, collection_owner.clone(), default_collection_config() )); @@ -2642,6 +2679,7 @@ fn approval_deadline_works() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), collection_config_from_disabled_settings(CollectionSetting::DepositRequired.into()) )); @@ -2698,6 +2736,7 @@ fn cancel_approval_works_with_admin() { Balances::make_free_balance_be(&item_owner, 100); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, collection_owner.clone(), default_collection_config() )); @@ -2789,6 +2828,7 @@ fn cancel_approval_works_with_force() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -2833,6 +2873,7 @@ fn clear_all_transfer_approvals_works() { new_test_ext().execute_with(|| { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, account(1), default_collection_config() )); @@ -2898,6 +2939,7 @@ fn clear_collection_approvals_works() { Balances::make_free_balance_be(&owner, balance); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, owner.clone(), default_collection_config() )); @@ -2990,6 +3032,7 @@ fn force_clear_collection_approvals_work() { Balances::make_free_balance_be(&owner, balance); assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, owner.clone(), default_collection_config() )); @@ -3084,6 +3127,7 @@ fn collection_item_works() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, user_id.clone(), default_collection_config() )); @@ -3112,6 +3156,7 @@ fn max_supply_should_work() { // validate set_collection_max_supply assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 0, user_id.clone(), default_collection_config() )); @@ -3185,6 +3230,7 @@ fn max_supply_should_work() { let collection_id = 1; assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), CollectionConfig { max_supply: Some(max_supply), ..default_collection_config() } )); @@ -3208,6 +3254,7 @@ fn mint_settings_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), default_collection_config() )); @@ -3229,6 +3276,7 @@ fn mint_settings_should_work() { let collection_id = 1; assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), CollectionConfig { mint_settings: MintSettings { @@ -3268,6 +3316,7 @@ fn set_price_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), default_collection_config() )); @@ -3336,6 +3385,7 @@ fn set_price_should_work() { let collection_id = 1; assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), collection_config_from_disabled_settings( CollectionSetting::TransferableItems | CollectionSetting::DepositRequired @@ -3383,6 +3433,7 @@ fn buy_item_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_1.clone(), default_collection_config() )); @@ -3608,6 +3659,7 @@ fn create_cancel_swap_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), default_collection_config() )); @@ -3766,6 +3818,7 @@ fn claim_swap_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_1.clone(), default_collection_config() )); @@ -3963,7 +4016,7 @@ fn various_collection_settings() { // when we set only one value it's required to call .into() on it let config = collection_config_from_disabled_settings(CollectionSetting::TransferableItems.into()); - assert_ok!(Nfts::force_create(RuntimeOrigin::root(), account(1), config)); + assert_ok!(Nfts::force_create(RuntimeOrigin::root(), 0, account(1), config)); let config = CollectionConfigOf::::get(0).unwrap(); assert!(!config.is_setting_enabled(CollectionSetting::TransferableItems)); @@ -3973,7 +4026,7 @@ fn various_collection_settings() { let config = collection_config_from_disabled_settings( CollectionSetting::UnlockedMetadata | CollectionSetting::TransferableItems, ); - assert_ok!(Nfts::force_create(RuntimeOrigin::root(), account(1), config)); + assert_ok!(Nfts::force_create(RuntimeOrigin::root(), 1, account(1), config)); let config = CollectionConfigOf::::get(1).unwrap(); assert!(!config.is_setting_enabled(CollectionSetting::TransferableItems)); @@ -3981,6 +4034,7 @@ fn various_collection_settings() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + 2, account(1), default_collection_config() )); @@ -3995,6 +4049,7 @@ fn collection_locking_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), collection_config_with_all_settings_enabled() )); @@ -4053,6 +4108,7 @@ fn pallet_level_feature_flags_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_id.clone(), default_collection_config() )); @@ -4150,6 +4206,7 @@ fn add_remove_item_attributes_approval_should_work() { assert_ok!(Nfts::force_create( RuntimeOrigin::root(), + collection_id, user_1.clone(), default_collection_config() )); @@ -4260,6 +4317,7 @@ fn pre_signed_mints_should_work() { Balances::make_free_balance_be(&user_2, 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(user_0.clone()), + 0, user_1.clone(), collection_config_with_all_settings_enabled(), )); @@ -4425,6 +4483,7 @@ fn pre_signed_attributes_should_work() { Balances::make_free_balance_be(&user_3, 100); assert_ok!(Nfts::create( RuntimeOrigin::signed(user_1.clone()), + collection_id, user_1.clone(), collection_config_with_all_settings_enabled(), )); @@ -4763,6 +4822,7 @@ fn clear_collection_metadata_works() { // Creating a collection increases owner deposit by 2 assert_ok!(Nfts::create( RuntimeOrigin::signed(account(1)), + 0, account(1), collection_config_with_all_settings_enabled() )); diff --git a/runtime/common/src/xcm/nonfungibles_adapter.rs b/runtime/common/src/xcm/nonfungibles_adapter.rs index e7f5512a..3eb1de65 100644 --- a/runtime/common/src/xcm/nonfungibles_adapter.rs +++ b/runtime/common/src/xcm/nonfungibles_adapter.rs @@ -1,9 +1,7 @@ -use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ ensure, - traits::{tokens::nonfungibles_v2, Get, Incrementable}, + traits::{tokens::nonfungibles_v2, Get}, }; -use scale_info::TypeInfo; use sp_std::{marker::PhantomData, prelude::*}; use xcm::latest::prelude::*; use xcm_builder::{AssetChecking, MintLocation}; @@ -12,53 +10,6 @@ use xcm_executor::{ AssetsInHolding, }; -#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo, MaxEncodedLen)] -/// Represents a collection ID based on a MultiLocation. -/// -/// This structure provides a way to map a MultiLocation to a collection ID, -/// which is useful for describing collections that do not follow an incremental pattern. -pub struct MultiLocationCollectionId(pub Location); - -impl MultiLocationCollectionId { - /// Consume `self` and return the inner MultiLocation. - pub fn into_inner(self) -> Location { - self.0 - } - - /// Return a reference to the inner MultiLocation. - pub fn inner(&self) -> &Location { - &self.0 - } -} - -impl From for MultiLocationCollectionId { - fn from(_: u16) -> Self { - unimplemented!("Not implemented. Requires for becnhmarking Helper config.") - } -} - -impl Incrementable for MultiLocationCollectionId { - fn increment(&self) -> Option { - None - } - - fn initial_value() -> Option { - None - } -} - -impl From for MultiLocationCollectionId { - fn from(value: Location) -> Self { - MultiLocationCollectionId(value) - } -} - -impl From for Location { - fn from(value: MultiLocationCollectionId) -> Location { - value.into_inner() - } -} - const LOG_TARGET: &str = "xcm::nonfungibles_adapter_pop"; /// Adapter for transferring non-fungible tokens (NFTs) using [`nonfungibles_v2`]. /// diff --git a/runtime/devnet/src/config/assets.rs b/runtime/devnet/src/config/assets.rs index 8c06bd91..741eb9e5 100644 --- a/runtime/devnet/src/config/assets.rs +++ b/runtime/devnet/src/config/assets.rs @@ -1,19 +1,18 @@ use cumulus_primitives_core::AssetInstance; use frame_support::{ parameter_types, - traits::{AsEnsureOriginWithArg, ConstU32, EnsureOrigin, EnsureOriginWithArg, Everything}, + traits::{AsEnsureOriginWithArg, ConstU32}, BoundedVec, PalletId, }; use frame_system::{EnsureRoot, EnsureSigned}; use pallet_nfts::PalletFeatures; use parachains_common::{AssetIdForTrustBackedAssets, CollectionId, ItemId, Signature}; -use pop_runtime_common::xcm::nonfungibles_adapter::MultiLocationCollectionId; use sp_runtime::traits::Verify; -use xcm_executor::traits::ConvertLocation; +use xcm::latest::Location; use crate::{ - config::xcm::LocationToAccountId, deposit, AccountId, Assets, Balance, Balances, BlockNumber, - Nfts, Runtime, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, DAYS, EXISTENTIAL_DEPOSIT, UNIT, + deposit, AccountId, Assets, Balance, Balances, BlockNumber, Nfts, Runtime, RuntimeEvent, + RuntimeHoldReason, DAYS, EXISTENTIAL_DEPOSIT, UNIT, }; /// We allow root to execute privileged asset operations. @@ -42,28 +41,6 @@ parameter_types! { pub const NftsMaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS; } -pub struct ForeignCreatorsNfts; - -impl EnsureOriginWithArg for ForeignCreatorsNfts { - type Success = AccountId; - - fn try_origin( - o: RuntimeOrigin, - a: &MultiLocationCollectionId, - ) -> sp_std::result::Result { - let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; - if !a.inner().starts_with(&origin_location.clone().try_into().unwrap()) { - return Err(o); - } - LocationToAccountId::convert_location(&origin_location).ok_or(o) - } - - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin(a: &MultiLocationCollectionId) -> Result { - Ok(pallet_xcm::Origin::Xcm(a.clone().into()).into()) - } -} - pub(crate) type ForeignNftsInstance = pallet_nfts::Instance2; pub type ForeignNftsCall = pallet_nfts::Call; impl pallet_nfts::Config for Runtime { @@ -73,8 +50,8 @@ impl pallet_nfts::Config for Runtime { type CollectionApprovalDeposit = NftsCollectionApprovalDeposit; type CollectionDeposit = NftsCollectionDeposit; // TODO: source from primitives - type CollectionId = MultiLocationCollectionId; - type CreateOrigin = ForeignCreatorsNfts; + type CollectionId = Location; + type CreateOrigin = AsEnsureOriginWithArg>; type Currency = Balances; type DepositPerByte = NftsDepositPerByte; type Features = NftsPalletFeatures; diff --git a/runtime/devnet/src/config/xcm.rs b/runtime/devnet/src/config/xcm.rs index bd65cff9..4eac8bbf 100644 --- a/runtime/devnet/src/config/xcm.rs +++ b/runtime/devnet/src/config/xcm.rs @@ -10,22 +10,17 @@ use pallet_nfts::ItemConfig; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; -use pop_runtime_common::xcm::nonfungibles_adapter::{ - MultiLocationCollectionId, NonFungiblesAdapterPop, -}; +use pop_runtime_common::xcm::nonfungibles_adapter::NonFungiblesAdapterPop; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, - AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; -use xcm_executor::{ - traits::{Error as MatchError, MatchesNonFungibles}, - XcmExecutor, -}; +use xcm_executor::{traits::JustTry, XcmExecutor}; use crate::{ AccountId, AllPalletsWithSystem, Balances, ForeignNfts, ParachainInfo, ParachainSystem, @@ -91,31 +86,10 @@ pub type XcmOriginToTransactDispatchOrigin = ( XcmPassthrough, ); -pub struct MultiAssetToNftsConverter; -impl MatchesNonFungibles for MultiAssetToNftsConverter { - fn matches_nonfungibles( - a: &Asset, - ) -> Result<(MultiLocationCollectionId, AssetInstance), MatchError> { - let (location, instance) = match (&a.id, &a.fun) { - (AssetId(location), NonFungible(instance)) => (location, instance), - _ => return Err(MatchError::AssetNotHandled), - }; - - let collection_id = MultiLocationCollectionId(Location { - parents: location.parents, - interior: location.interior.clone().try_into().unwrap(), - }); - - let item_id = instance; - - Ok((collection_id, *item_id)) - } -} - pub type NonFungiblesTransactor = NonFungiblesAdapterPop< // Use the non-fungibles pallet: ForeignNfts, - MultiAssetToNftsConverter, + ConvertedConcreteId, // Convert an XCM Location into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly):