diff --git a/frame/nfts/src/impl_nonfungibles.rs b/frame/nfts/src/impl_nonfungibles.rs index ef6bbe7656ef8..865d0681880bb 100644 --- a/frame/nfts/src/impl_nonfungibles.rs +++ b/frame/nfts/src/impl_nonfungibles.rs @@ -133,7 +133,8 @@ impl, I: 'static> Inspect<::AccountId> for Palle impl, I: 'static> Create<::AccountId, CollectionConfigFor> for Pallet { - /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin` with + /// collection settings provided in `config`. fn create_collection( who: &T::AccountId, admin: &T::AccountId, @@ -159,6 +160,27 @@ impl, I: 'static> Create<::AccountId, Collection Ok(collection) } } +impl, I: 'static> CreateSimplified<::AccountId> for Pallet { + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin` with + /// default collection settings. + fn create_collection( + who: &T::AccountId, + admin: &T::AccountId, + ) -> Result { + let collection = + NextCollectionId::::get().unwrap_or(T::CollectionId::initial_value()); + + Self::do_create_collection( + collection, + who.clone(), + admin.clone(), + CollectionConfigFor::::default(), + T::CollectionDeposit::get(), + Event::Created { collection, creator: who.clone(), owner: admin.clone() }, + )?; + Ok(collection) + } +} impl, I: 'static> Destroy<::AccountId> for Pallet { type DestroyWitness = DestroyWitness; @@ -181,9 +203,13 @@ impl, I: 'static> Mutate<::AccountId, ItemConfig collection: &Self::CollectionId, item: &Self::ItemId, who: &T::AccountId, - item_config: &ItemConfig, + item_config: Option<&ItemConfig>, deposit_collection_owner: bool, ) -> DispatchResult { + let item_config = match item_config { + Some(item_config) => *item_config, + None => ItemConfig { settings: Self::get_default_item_settings(&collection)? }, + }; Self::do_mint( *collection, *item, @@ -192,7 +218,7 @@ impl, I: 'static> Mutate<::AccountId, ItemConfig false => Some(who.clone()), }, who.clone(), - *item_config, + item_config, |_, _| Ok(()), ) } diff --git a/frame/nfts/src/types.rs b/frame/nfts/src/types.rs index f8ab2a355b48b..5bfae2e089837 100644 --- a/frame/nfts/src/types.rs +++ b/frame/nfts/src/types.rs @@ -347,9 +347,7 @@ pub enum PalletAttributes { } /// Collection's configuration. -#[derive( - Clone, Copy, Decode, Default, Encode, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo, -)] +#[derive(Clone, Copy, Decode, Encode, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)] pub struct CollectionConfig { /// Collection's settings. pub settings: CollectionSettings, @@ -359,6 +357,18 @@ pub struct CollectionConfig { pub mint_settings: MintSettings, } +impl Default + for CollectionConfig +{ + fn default() -> Self { + Self { + settings: CollectionSettings::all_enabled(), + max_supply: None, + mint_settings: MintSettings::default(), + } + } +} + impl CollectionConfig { pub fn is_setting_enabled(&self, setting: CollectionSetting) -> bool { !self.settings.is_disabled(setting) @@ -409,14 +419,18 @@ impl ItemSettings { impl_codec_bitflags!(ItemSettings, u64, ItemSetting); /// Item's configuration. -#[derive( - Encode, Decode, Default, PartialEq, RuntimeDebug, Clone, Copy, MaxEncodedLen, TypeInfo, -)] +#[derive(Encode, Decode, PartialEq, RuntimeDebug, Clone, Copy, MaxEncodedLen, TypeInfo)] pub struct ItemConfig { /// Item's settings. pub settings: ItemSettings, } +impl Default for ItemConfig { + fn default() -> Self { + Self { settings: ItemSettings::all_enabled() } + } +} + impl ItemConfig { pub fn is_setting_enabled(&self, setting: ItemSetting) -> bool { !self.settings.is_disabled(setting) diff --git a/frame/support/src/traits/tokens/nonfungible_v2.rs b/frame/support/src/traits/tokens/nonfungible_v2.rs index c23bf3e4055b1..b0fdd8a6aac61 100644 --- a/frame/support/src/traits/tokens/nonfungible_v2.rs +++ b/frame/support/src/traits/tokens/nonfungible_v2.rs @@ -122,12 +122,13 @@ pub trait InspectEnumerable: Inspect { /// attributes set on them. pub trait Mutate: Inspect { /// Mint some `item` to be owned by `who`. + /// When `config` set to `None` it will use the collection's default_item_settings. /// /// By default, this is not a supported operation. fn mint_into( _item: &Self::ItemId, _who: &AccountId, - _config: &ItemConfig, + _config: Option<&ItemConfig>, _deposit_collection_owner: bool, ) -> DispatchResult { Err(TokenError::Unsupported.into()) @@ -257,7 +258,7 @@ impl< fn mint_into( item: &Self::ItemId, who: &AccountId, - config: &ItemConfig, + config: Option<&ItemConfig>, deposit_collection_owner: bool, ) -> DispatchResult { >::mint_into( diff --git a/frame/support/src/traits/tokens/nonfungibles_v2.rs b/frame/support/src/traits/tokens/nonfungibles_v2.rs index 9d32f29becd4c..df31f8517291c 100644 --- a/frame/support/src/traits/tokens/nonfungibles_v2.rs +++ b/frame/support/src/traits/tokens/nonfungibles_v2.rs @@ -182,7 +182,8 @@ pub trait InspectEnumerable: Inspect { /// Trait for providing the ability to create collections of nonfungible items. pub trait Create: Inspect { - /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin` with + /// collection settings provided in `config`. fn create_collection( who: &AccountId, admin: &AccountId, @@ -190,6 +191,16 @@ pub trait Create: Inspect { ) -> Result; } +/// A simplified trait for providing the ability to create collections of nonfungible items. +pub trait CreateSimplified: Inspect { + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin` with + /// default collection settings. + fn create_collection( + who: &AccountId, + admin: &AccountId, + ) -> Result; +} + /// Trait for providing the ability to destroy collections of nonfungible items. pub trait Destroy: Inspect { /// The witness data needed to destroy an item. @@ -219,13 +230,14 @@ pub trait Destroy: Inspect { /// minted, burned and/or have attributes set on them. pub trait Mutate: Inspect { /// Mint some `item` of `collection` to be owned by `who`. + /// When `config` set to `None` it will use the collection's default_item_settings. /// /// By default, this is not a supported operation. fn mint_into( _collection: &Self::CollectionId, _item: &Self::ItemId, _who: &AccountId, - _config: &ItemConfig, + _config: Option<&ItemConfig>, _deposit_collection_owner: bool, ) -> DispatchResult { Err(TokenError::Unsupported.into())