Repository: paritytech/substrate
File: frame/nfts/src/features/create_delete_collection.rs (Rust)

Code before:
			collection,
			admin,
			CollectionRoles(
				CollectionRole::Admin | CollectionRole::Freezer | CollectionRole::Issuer,
			),
		);

		CollectionConfigOf::<T, I>::insert(&collection, config);
		CollectionAccount::<T, I>::insert(&owner, &collection, ());
		Self::deposit_event(event);
		Ok(())
	}

	/// Destroy the specified collection with the given `collection`, `witness`, and
	/// `maybe_check_owner`.
	///
	/// This function destroys the specified collection if it exists and meets the necessary
	/// conditions. It checks the provided `witness` against the actual collection details and
	/// removes the collection along with its associated metadata, attributes, and configurations.
	/// The necessary deposits are returned to the corresponding accounts, and the roles and
	/// configurations for the collection are cleared. Finally, it emits the `Destroyed` event upon
	/// successful destruction.
	///
	/// # Errors
	///
	/// This function returns an error in the following cases:
	/// - If the collection ID is not found (`UnknownCollection`).
	/// - If the provided `maybe_check_owner` does not match the actual owner (`NoPermission`).
	/// - If the collection is not empty (contains items) (`CollectionNotEmpty`).
	/// - If the `witness` does not match the actual collection details (`BadWitness`).
	pub fn do_destroy_collection(
		collection: T::CollectionId,
		witness: DestroyWitness,
		maybe_check_owner: Option<T::AccountId>,
	) -> Result<DestroyWitness, DispatchError> {
		Collection::<T, I>::try_mutate_exists(collection, |maybe_details| {
			let collection_details =
				maybe_details.take().ok_or(Error::<T, I>::UnknownCollection)?;
			if let Some(check_owner) = maybe_check_owner {
				ensure!(collection_details.owner == check_owner, Error::<T, I>::NoPermission);
			}
			ensure!(collection_details.items == 0, Error::<T, I>::CollectionNotEmpty);
			ensure!(collection_details.attributes == witness.attributes, Error::<T, I>::BadWitness);
			ensure!(
				collection_details.item_metadatas == witness.item_metadatas,
				Error::<T, I>::BadWitness
			);
			ensure!(
				collection_details.item_configs == witness.item_configs,
				Error::<T, I>::BadWitness
			);

Review comment (suggestion):
```suggestion
	/// This function returns a `Dispatch` error in the following cases:
```

Code after:
		CollectionRoleOf::<T, I>::insert(
			collection,
			admin,
			CollectionRoles(
				CollectionRole::Admin | CollectionRole::Freezer | CollectionRole::Issuer,
			),
		);

		CollectionConfigOf::<T, I>::insert(&collection, config);
		CollectionAccount::<T, I>::insert(&owner, &collection, ());
		Self::deposit_event(event);
		Ok(())
	}

	/// Destroy the specified collection with the given `collection`, `witness`, and
	/// `maybe_check_owner`.
	///
	/// This function destroys the specified collection if it exists and meets the necessary
	/// conditions. It checks the provided `witness` against the actual collection details and
	/// removes the collection along with its associated metadata, attributes, and configurations.
	/// The necessary deposits are returned to the corresponding accounts, and the roles and
	/// configurations for the collection are cleared. Finally, it emits the `Destroyed` event upon
	/// successful destruction.
	///
	/// # Errors
	///
	/// This function returns a dispatch error in the following cases:
	/// - If the collection ID is not found
	///   ([`UnknownCollection`](crate::Error::UnknownCollection)).
	/// - If the provided `maybe_check_owner` does not match the actual owner
	///   ([`NoPermission`](crate::Error::NoPermission)).
	/// - If the collection is not empty (contains items)
	///   ([`CollectionNotEmpty`](crate::Error::CollectionNotEmpty)).
	/// - If the `witness` does not match the actual collection details
	///   ([`BadWitness`](crate::Error::BadWitness)).
	pub fn do_destroy_collection(
		collection: T::CollectionId,
		witness: DestroyWitness,
		maybe_check_owner: Option<T::AccountId>,
	) -> Result<DestroyWitness, DispatchError> {
		Collection::<T, I>::try_mutate_exists(collection, |maybe_details| {
			let collection_details =
				maybe_details.take().ok_or(Error::<T, I>::UnknownCollection)?;
			if let Some(check_owner) = maybe_check_owner {
				ensure!(collection_details.owner == check_owner, Error::<T, I>::NoPermission);
			}
			ensure!(collection_details.items == 0, Error::<T, I>::CollectionNotEmpty);
			ensure!(collection_details.attributes == witness.attributes, Error::<T, I>::BadWitness);
			ensure!(
				collection_details.item_metadatas == witness.item_metadatas,
				Error::<T, I>::BadWitness