Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[fix lint warnings: NFTs pallet] fix clippy::missing_errors_doc lint warnings #14648

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frame/nfts/src/common_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Collection::<T, I>::get(collection).map(|i| i.owner)
}

/// Validate the `data` was signed by `signer` and the `signature` is correct.
/// Validates the signature of the given data with the provided signer's account ID.
///
/// # Errors
///
/// This function returns a [`WrongSignature`](crate::Error::WrongSignature) error if the
/// signature is invalid or the verification process fails.
pub fn validate_signature(
data: &Vec<u8>,
signature: &T::OffchainSignature,
Expand Down
19 changes: 17 additions & 2 deletions frame/nfts/src/features/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,21 +381,36 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(result)
}

/// A helper method to construct attribute's key.
/// A helper method to construct an attribute's key.
///
/// # Errors
///
/// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the
/// provided attribute `key` is too long.
pub fn construct_attribute_key(
key: Vec<u8>,
) -> Result<BoundedVec<u8, T::KeyLimit>, DispatchError> {
Ok(BoundedVec::try_from(key).map_err(|_| Error::<T, I>::IncorrectData)?)
}

/// A helper method to construct attribute's value.
/// A helper method to construct an attribute's value.
///
/// # Errors
///
/// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the
/// provided `value` is too long.
pub fn construct_attribute_value(
value: Vec<u8>,
) -> Result<BoundedVec<u8, T::ValueLimit>, DispatchError> {
Ok(BoundedVec::try_from(value).map_err(|_| Error::<T, I>::IncorrectData)?)
}

/// A helper method to check whether a system attribute is set for a given item.
///
/// # Errors
///
/// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the
/// provided pallet attribute is too long.
pub fn has_system_attribute(
collection: &T::CollectionId,
item: &T::ItemId,
Expand Down
32 changes: 32 additions & 0 deletions frame/nfts/src/features/create_delete_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ use crate::*;
use frame_support::pallet_prelude::*;

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Create a new collection with the given `collection`, `owner`, `admin`, `config`, `deposit`,
/// and `event`.
///
/// This function creates a new collection with the provided parameters. It reserves the
/// required deposit from the owner's account, sets the collection details, assigns admin roles,
/// and inserts the provided configuration. Finally, it emits the specified event upon success.
///
/// # Errors
///
/// This function returns a [`CollectionIdInUse`](crate::Error::CollectionIdInUse) error if the
/// collection ID is already in use.
pub fn do_create_collection(
collection: T::CollectionId,
owner: T::AccountId,
Expand Down Expand Up @@ -56,6 +67,27 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
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,
Expand Down
26 changes: 26 additions & 0 deletions frame/nfts/src/features/create_delete_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ use crate::*;
use frame_support::{pallet_prelude::*, traits::ExistenceRequirement};

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Mint a new unique item with the given `collection`, `item`, and other minting configuration
/// details.
///
/// This function performs the minting of a new unique item. It checks if the item does not
/// already exist in the given collection, and if the max supply limit (if configured) is not
/// reached. It also reserves the required deposit for the item and sets the item details
/// accordingly.
///
/// # Errors
///
/// This function returns a dispatch error in the following cases:
/// - If the collection ID is invalid ([`UnknownCollection`](crate::Error::UnknownCollection)).
/// - If the item already exists in the collection
/// ([`AlreadyExists`](crate::Error::AlreadyExists)).
/// - If the item configuration already exists
/// ([`InconsistentItemConfig`](crate::Error::InconsistentItemConfig)).
/// - If the max supply limit (if configured) for the collection is reached
/// ([`MaxSupplyReached`](crate::Error::MaxSupplyReached)).
/// - If any error occurs in the `with_details_and_config` closure.
pub fn do_mint(
collection: T::CollectionId,
item: T::ItemId,
Expand Down Expand Up @@ -163,6 +182,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(())
}

/// Burns the specified item with the given `collection`, `item`, and `with_details`.
///
/// # Errors
///
/// This function returns a dispatch error in the following cases:
/// - If the collection ID is invalid ([`UnknownCollection`](crate::Error::UnknownCollection)).
/// - If the item is locked ([`ItemLocked`](crate::Error::ItemLocked)).
pub fn do_burn(
collection: T::CollectionId,
item: T::ItemId,
Expand Down
5 changes: 5 additions & 0 deletions frame/nfts/src/features/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

/// A helper method to construct metadata.
///
/// # Errors
///
/// This function returns an [`IncorrectMetadata`](crate::Error::IncorrectMetadata) dispatch
/// error if the provided metadata is too long.
pub fn construct_metadata(
metadata: Vec<u8>,
) -> Result<BoundedVec<u8, T::StringLimit>, DispatchError> {
Expand Down
11 changes: 11 additions & 0 deletions frame/nfts/src/features/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ use crate::*;
use frame_support::pallet_prelude::*;

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Performs the transfer action for the given `collection`, `item`, `dest`, and `event`.
///
/// # Errors
///
/// This function returns a dispatch error in the following cases:
/// - If the collection ID is invalid ([`UnknownCollection`](crate::Error::UnknownCollection)).
/// - If the item ID is invalid ([`UnknownItem`](crate::Error::UnknownItem)).
/// - If the item is locked or transferring it is disabled
/// ([`ItemLocked`](crate::Error::ItemLocked)).
/// - If the collection or item is non-transferable
/// ([`ItemsNonTransferable`](crate::Error::ItemsNonTransferable)).
pub fn do_transfer(
collection: T::CollectionId,
item: T::ItemId,
Expand Down