From 0d0f5b966226c673e851403cd7b19f74ef405e73 Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Wed, 26 Jul 2023 17:36:19 +0200 Subject: [PATCH 1/9] fix missing errors doc warnings --- frame/nfts/src/common_functions.rs | 6 +++- frame/nfts/src/features/attributes.rs | 16 +++++++++-- .../src/features/create_delete_collection.rs | 28 ++++++++++++++++++- frame/nfts/src/features/create_delete_item.rs | 22 +++++++++++++++ frame/nfts/src/features/metadata.rs | 4 +++ frame/nfts/src/features/transfer.rs | 9 ++++++ 6 files changed, 81 insertions(+), 4 deletions(-) diff --git a/frame/nfts/src/common_functions.rs b/frame/nfts/src/common_functions.rs index b3dcef4cf324c..dfdadf6daa63c 100644 --- a/frame/nfts/src/common_functions.rs +++ b/frame/nfts/src/common_functions.rs @@ -31,7 +31,11 @@ impl, I: 'static> Pallet { Collection::::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` error if the signature is invalid or the verification process fails. pub fn validate_signature( data: &Vec, signature: &T::OffchainSignature, diff --git a/frame/nfts/src/features/attributes.rs b/frame/nfts/src/features/attributes.rs index 8a9bbe8a61de0..9d7b4771a967c 100644 --- a/frame/nfts/src/features/attributes.rs +++ b/frame/nfts/src/features/attributes.rs @@ -381,14 +381,22 @@ impl, I: 'static> Pallet { 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` error if the provided attribute `key` is incorrectly formatted. pub fn construct_attribute_key( key: Vec, ) -> Result, DispatchError> { Ok(BoundedVec::try_from(key).map_err(|_| Error::::IncorrectData)?) } - /// A helper method to construct attribute's value. + /// A helper method to construct an attribute's value. + /// + /// # Errors + /// + /// This function returns an `IncorrectData` error if the provided `value` is incorrectly formatted. pub fn construct_attribute_value( value: Vec, ) -> Result, DispatchError> { @@ -396,6 +404,10 @@ impl, I: 'static> Pallet { } /// A helper method to check whether a system attribute is set for a given item. + /// + /// # Errors + /// + /// This function returns an `IncorrectData` error if the provided pallet attribute is incorrectly formatted. pub fn has_system_attribute( collection: &T::CollectionId, item: &T::ItemId, diff --git a/frame/nfts/src/features/create_delete_collection.rs b/frame/nfts/src/features/create_delete_collection.rs index aadad58689b43..1f8d56ca1e53c 100644 --- a/frame/nfts/src/features/create_delete_collection.rs +++ b/frame/nfts/src/features/create_delete_collection.rs @@ -19,6 +19,16 @@ use crate::*; use frame_support::pallet_prelude::*; impl, I: 'static> Pallet { + /// 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` error if the collection ID is already in use. pub fn do_create_collection( collection: T::CollectionId, owner: T::AccountId, @@ -55,7 +65,23 @@ impl, I: 'static> Pallet { 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, diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index e3d1334d48ef5..190ef3a86be66 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -19,6 +19,21 @@ use crate::*; use frame_support::{pallet_prelude::*, traits::ExistenceRequirement}; impl, I: 'static> Pallet { + /// 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 an error in the following cases: + /// - If the collection ID is invalid (`UnknownCollection`). + /// - If the item already exists in the collection (`AlreadyExists`). + /// - If the item configuration already exists (`InconsistentItemConfig`). + /// - If the max supply limit (if configured) for the collection is reached (`MaxSupplyReached`). + /// - If any error occurs in the `with_details_and_config` closure. pub fn do_mint( collection: T::CollectionId, item: T::ItemId, @@ -163,6 +178,13 @@ impl, I: 'static> Pallet { Ok(()) } + /// Burns the specified item with the given `collection`, `item`, and `with_details`. + /// + /// # Errors + /// + /// This function returns an error in the following cases: + /// - If the collection ID is invalid (`UnknownCollection`) + /// - If the item is locked (`ItemLocked`) pub fn do_burn( collection: T::CollectionId, item: T::ItemId, diff --git a/frame/nfts/src/features/metadata.rs b/frame/nfts/src/features/metadata.rs index fde0296784d11..54f34773a7cf8 100644 --- a/frame/nfts/src/features/metadata.rs +++ b/frame/nfts/src/features/metadata.rs @@ -209,6 +209,10 @@ impl, I: 'static> Pallet { } /// A helper method to construct metadata. + /// + /// # Errors + /// + /// This function returns a `IncorrectMetadata` error if the provided metadata is incorrectly formatted. pub fn construct_metadata( metadata: Vec, ) -> Result, DispatchError> { diff --git a/frame/nfts/src/features/transfer.rs b/frame/nfts/src/features/transfer.rs index 69209e1bb6c4b..098d04b9d5ca7 100644 --- a/frame/nfts/src/features/transfer.rs +++ b/frame/nfts/src/features/transfer.rs @@ -19,6 +19,15 @@ use crate::*; use frame_support::pallet_prelude::*; impl, I: 'static> Pallet { + /// Performs the transfer action for the given `collection`, `item`, `dest`, and `event`. + /// + /// # Errors + /// + /// This function returns an error in the following cases: + /// - If the collection ID is invalid (`UnknownCollection`) + /// - If the item ID is invalid (`UnknownItem`). + /// - If the item is locked or transferring it is disabled (`ItemLocked`). + /// - If the collection or item is non-transferable (`ItemsNonTransferable`). pub fn do_transfer( collection: T::CollectionId, item: T::ItemId, From e0b2cee82a1361581a2fe10a0cf3425dbbd8897f Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Wed, 26 Jul 2023 17:39:30 +0200 Subject: [PATCH 2/9] cargo +nightly fmt --- frame/nfts/src/common_functions.rs | 3 ++- frame/nfts/src/features/attributes.rs | 9 ++++++--- frame/nfts/src/features/create_delete_collection.rs | 5 +++-- frame/nfts/src/features/create_delete_item.rs | 6 ++++-- frame/nfts/src/features/metadata.rs | 3 ++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frame/nfts/src/common_functions.rs b/frame/nfts/src/common_functions.rs index dfdadf6daa63c..40538ae07fda8 100644 --- a/frame/nfts/src/common_functions.rs +++ b/frame/nfts/src/common_functions.rs @@ -35,7 +35,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `WrongSignature` error if the signature is invalid or the verification process fails. + /// This function returns a `WrongSignature` error if the signature is invalid or the + /// verification process fails. pub fn validate_signature( data: &Vec, signature: &T::OffchainSignature, diff --git a/frame/nfts/src/features/attributes.rs b/frame/nfts/src/features/attributes.rs index 9d7b4771a967c..6c5afc9463bba 100644 --- a/frame/nfts/src/features/attributes.rs +++ b/frame/nfts/src/features/attributes.rs @@ -385,7 +385,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided attribute `key` is incorrectly formatted. + /// This function returns an `IncorrectData` error if the provided attribute `key` is + /// incorrectly formatted. pub fn construct_attribute_key( key: Vec, ) -> Result, DispatchError> { @@ -396,7 +397,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided `value` is incorrectly formatted. + /// This function returns an `IncorrectData` error if the provided `value` is incorrectly + /// formatted. pub fn construct_attribute_value( value: Vec, ) -> Result, DispatchError> { @@ -407,7 +409,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided pallet attribute is incorrectly formatted. + /// This function returns an `IncorrectData` error if the provided pallet attribute is + /// incorrectly formatted. pub fn has_system_attribute( collection: &T::CollectionId, item: &T::ItemId, diff --git a/frame/nfts/src/features/create_delete_collection.rs b/frame/nfts/src/features/create_delete_collection.rs index 1f8d56ca1e53c..a9e3c321a65f5 100644 --- a/frame/nfts/src/features/create_delete_collection.rs +++ b/frame/nfts/src/features/create_delete_collection.rs @@ -65,8 +65,9 @@ impl, I: 'static> Pallet { Self::deposit_event(event); Ok(()) } - - /// Destroy the specified collection with the given `collection`, `witness`, and `maybe_check_owner`. + + /// 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 diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index 190ef3a86be66..ce7cae8fd450a 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -19,7 +19,8 @@ use crate::*; use frame_support::{pallet_prelude::*, traits::ExistenceRequirement}; impl, I: 'static> Pallet { - /// Mint a new unique item with the given `collection`, `item`, and other minting configuration details. + /// 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 @@ -32,7 +33,8 @@ impl, I: 'static> Pallet { /// - If the collection ID is invalid (`UnknownCollection`). /// - If the item already exists in the collection (`AlreadyExists`). /// - If the item configuration already exists (`InconsistentItemConfig`). - /// - If the max supply limit (if configured) for the collection is reached (`MaxSupplyReached`). + /// - If the max supply limit (if configured) for the collection is reached + /// (`MaxSupplyReached`). /// - If any error occurs in the `with_details_and_config` closure. pub fn do_mint( collection: T::CollectionId, diff --git a/frame/nfts/src/features/metadata.rs b/frame/nfts/src/features/metadata.rs index 54f34773a7cf8..d480a66bc6a34 100644 --- a/frame/nfts/src/features/metadata.rs +++ b/frame/nfts/src/features/metadata.rs @@ -212,7 +212,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `IncorrectMetadata` error if the provided metadata is incorrectly formatted. + /// This function returns a `IncorrectMetadata` error if the provided metadata is incorrectly + /// formatted. pub fn construct_metadata( metadata: Vec, ) -> Result, DispatchError> { From 49f4f237985b74f4774e9714ad493bf4deb8be8c Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Thu, 27 Jul 2023 14:51:44 +0200 Subject: [PATCH 3/9] Update frame/nfts/src/features/create_delete_item.rs --- frame/nfts/src/features/create_delete_item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index ce7cae8fd450a..470e292736395 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -29,7 +29,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an error in the following cases: + /// This function returns a `Dispatch` error in the following cases: /// - If the collection ID is invalid (`UnknownCollection`). /// - If the item already exists in the collection (`AlreadyExists`). /// - If the item configuration already exists (`InconsistentItemConfig`). From 6b6fa7c874d6153ffe5741be70b0e2035037358d Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Thu, 27 Jul 2023 14:51:49 +0200 Subject: [PATCH 4/9] Update frame/nfts/src/features/create_delete_item.rs --- frame/nfts/src/features/create_delete_item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index 470e292736395..c61af2938f2bc 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -184,7 +184,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an error in the following cases: + /// This function returns a `Dispatch` error in the following cases: /// - If the collection ID is invalid (`UnknownCollection`) /// - If the item is locked (`ItemLocked`) pub fn do_burn( From fbf2df396ea86f453bac8135b24105fb2f91f773 Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Thu, 27 Jul 2023 14:51:57 +0200 Subject: [PATCH 5/9] Update frame/nfts/src/features/transfer.rs --- frame/nfts/src/features/transfer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nfts/src/features/transfer.rs b/frame/nfts/src/features/transfer.rs index 098d04b9d5ca7..fee8cc24eae8c 100644 --- a/frame/nfts/src/features/transfer.rs +++ b/frame/nfts/src/features/transfer.rs @@ -23,7 +23,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an error in the following cases: + /// This function returns a `Dispatch` error in the following cases: /// - If the collection ID is invalid (`UnknownCollection`) /// - If the item ID is invalid (`UnknownItem`). /// - If the item is locked or transferring it is disabled (`ItemLocked`). From f096a2bcf902f566608600fb6ba5847d8ba2e892 Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Thu, 27 Jul 2023 14:52:06 +0200 Subject: [PATCH 6/9] Update frame/nfts/src/features/create_delete_collection.rs --- frame/nfts/src/features/create_delete_collection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nfts/src/features/create_delete_collection.rs b/frame/nfts/src/features/create_delete_collection.rs index a9e3c321a65f5..2beb874c25537 100644 --- a/frame/nfts/src/features/create_delete_collection.rs +++ b/frame/nfts/src/features/create_delete_collection.rs @@ -78,7 +78,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an error in the following cases: + /// This function returns a `Dispatch` 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`). From 9293a280941a19f349ccbd45b1e12ff4e51810da Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Mon, 14 Aug 2023 18:08:23 +0200 Subject: [PATCH 7/9] add intra doc linking for errors --- frame/nfts/src/common_functions.rs | 2 +- frame/nfts/src/features/attributes.rs | 6 +++--- .../src/features/create_delete_collection.rs | 12 ++++++------ frame/nfts/src/features/create_delete_item.rs | 17 ++++++++--------- frame/nfts/src/features/metadata.rs | 2 +- frame/nfts/src/features/transfer.rs | 10 +++++----- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/frame/nfts/src/common_functions.rs b/frame/nfts/src/common_functions.rs index 40538ae07fda8..fd6eccfea7bd3 100644 --- a/frame/nfts/src/common_functions.rs +++ b/frame/nfts/src/common_functions.rs @@ -35,7 +35,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `WrongSignature` error if the signature is invalid or the + /// 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, diff --git a/frame/nfts/src/features/attributes.rs b/frame/nfts/src/features/attributes.rs index 6c5afc9463bba..0123823d64f76 100644 --- a/frame/nfts/src/features/attributes.rs +++ b/frame/nfts/src/features/attributes.rs @@ -385,7 +385,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided attribute `key` is + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided attribute `key` is /// incorrectly formatted. pub fn construct_attribute_key( key: Vec, @@ -397,7 +397,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided `value` is incorrectly + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided `value` is incorrectly /// formatted. pub fn construct_attribute_value( value: Vec, @@ -409,7 +409,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an `IncorrectData` error if the provided pallet attribute is + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided pallet attribute is /// incorrectly formatted. pub fn has_system_attribute( collection: &T::CollectionId, diff --git a/frame/nfts/src/features/create_delete_collection.rs b/frame/nfts/src/features/create_delete_collection.rs index 2beb874c25537..78c0de9b9c78c 100644 --- a/frame/nfts/src/features/create_delete_collection.rs +++ b/frame/nfts/src/features/create_delete_collection.rs @@ -28,7 +28,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `CollectionIdInUse` error if the collection ID is already in use. + /// 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, @@ -78,11 +78,11 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `Dispatch` 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`). + /// 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, diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index c61af2938f2bc..3e995dd64bb62 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -29,12 +29,11 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `Dispatch` error in the following cases: - /// - If the collection ID is invalid (`UnknownCollection`). - /// - If the item already exists in the collection (`AlreadyExists`). - /// - If the item configuration already exists (`InconsistentItemConfig`). - /// - If the max supply limit (if configured) for the collection is reached - /// (`MaxSupplyReached`). + /// 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, @@ -184,9 +183,9 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `Dispatch` error in the following cases: - /// - If the collection ID is invalid (`UnknownCollection`) - /// - If the item is locked (`ItemLocked`) + /// 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, diff --git a/frame/nfts/src/features/metadata.rs b/frame/nfts/src/features/metadata.rs index d480a66bc6a34..677ace041d266 100644 --- a/frame/nfts/src/features/metadata.rs +++ b/frame/nfts/src/features/metadata.rs @@ -212,7 +212,7 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `IncorrectMetadata` error if the provided metadata is incorrectly + /// This function returns an [`IncorrectMetadata`](crate::Error::IncorrectMetadata) dispatch error if the provided metadata is incorrectly /// formatted. pub fn construct_metadata( metadata: Vec, diff --git a/frame/nfts/src/features/transfer.rs b/frame/nfts/src/features/transfer.rs index fee8cc24eae8c..717fec30119c8 100644 --- a/frame/nfts/src/features/transfer.rs +++ b/frame/nfts/src/features/transfer.rs @@ -23,11 +23,11 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a `Dispatch` error in the following cases: - /// - If the collection ID is invalid (`UnknownCollection`) - /// - If the item ID is invalid (`UnknownItem`). - /// - If the item is locked or transferring it is disabled (`ItemLocked`). - /// - If the collection or item is non-transferable (`ItemsNonTransferable`). + /// 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, From ca6a87576d2157f6f29d26d47d380df968f0378a Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Mon, 14 Aug 2023 18:09:15 +0200 Subject: [PATCH 8/9] fmt --- frame/nfts/src/common_functions.rs | 4 ++-- frame/nfts/src/features/attributes.rs | 12 ++++++------ .../nfts/src/features/create_delete_collection.rs | 15 ++++++++++----- frame/nfts/src/features/create_delete_item.rs | 9 ++++++--- frame/nfts/src/features/metadata.rs | 4 ++-- frame/nfts/src/features/transfer.rs | 6 ++++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/frame/nfts/src/common_functions.rs b/frame/nfts/src/common_functions.rs index fd6eccfea7bd3..1ad523d664c7c 100644 --- a/frame/nfts/src/common_functions.rs +++ b/frame/nfts/src/common_functions.rs @@ -35,8 +35,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a [`WrongSignature`](crate::Error::WrongSignature) error if the signature is invalid or the - /// verification process fails. + /// 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, signature: &T::OffchainSignature, diff --git a/frame/nfts/src/features/attributes.rs b/frame/nfts/src/features/attributes.rs index 0123823d64f76..58399a2e8c56a 100644 --- a/frame/nfts/src/features/attributes.rs +++ b/frame/nfts/src/features/attributes.rs @@ -385,8 +385,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided attribute `key` is - /// incorrectly formatted. + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the + /// provided attribute `key` is incorrectly formatted. pub fn construct_attribute_key( key: Vec, ) -> Result, DispatchError> { @@ -397,8 +397,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided `value` is incorrectly - /// formatted. + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the + /// provided `value` is incorrectly formatted. pub fn construct_attribute_value( value: Vec, ) -> Result, DispatchError> { @@ -409,8 +409,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the provided pallet attribute is - /// incorrectly formatted. + /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the + /// provided pallet attribute is incorrectly formatted. pub fn has_system_attribute( collection: &T::CollectionId, item: &T::ItemId, diff --git a/frame/nfts/src/features/create_delete_collection.rs b/frame/nfts/src/features/create_delete_collection.rs index 78c0de9b9c78c..9815958aac7bb 100644 --- a/frame/nfts/src/features/create_delete_collection.rs +++ b/frame/nfts/src/features/create_delete_collection.rs @@ -28,7 +28,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns a [`CollectionIdInUse`](crate::Error::CollectionIdInUse) error if the collection ID is already in use. + /// 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, @@ -79,10 +80,14 @@ impl, I: 'static> Pallet { /// # 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)). + /// - 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, diff --git a/frame/nfts/src/features/create_delete_item.rs b/frame/nfts/src/features/create_delete_item.rs index 3e995dd64bb62..33af70a91346c 100644 --- a/frame/nfts/src/features/create_delete_item.rs +++ b/frame/nfts/src/features/create_delete_item.rs @@ -31,9 +31,12 @@ impl, I: 'static> Pallet { /// /// 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 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, diff --git a/frame/nfts/src/features/metadata.rs b/frame/nfts/src/features/metadata.rs index 677ace041d266..ec1ff3a307a16 100644 --- a/frame/nfts/src/features/metadata.rs +++ b/frame/nfts/src/features/metadata.rs @@ -212,8 +212,8 @@ impl, I: 'static> Pallet { /// /// # Errors /// - /// This function returns an [`IncorrectMetadata`](crate::Error::IncorrectMetadata) dispatch error if the provided metadata is incorrectly - /// formatted. + /// This function returns an [`IncorrectMetadata`](crate::Error::IncorrectMetadata) dispatch + /// error if the provided metadata is incorrectly formatted. pub fn construct_metadata( metadata: Vec, ) -> Result, DispatchError> { diff --git a/frame/nfts/src/features/transfer.rs b/frame/nfts/src/features/transfer.rs index 717fec30119c8..149dbb9646fa2 100644 --- a/frame/nfts/src/features/transfer.rs +++ b/frame/nfts/src/features/transfer.rs @@ -26,8 +26,10 @@ impl, I: 'static> Pallet { /// 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)). + /// - 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, From 52cb5329e2e83aa221096b1f0594b5deb4e60e67 Mon Sep 17 00:00:00 2001 From: Sacha Lansky Date: Tue, 15 Aug 2023 09:40:09 +0200 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Oliver Tale-Yazdi --- frame/nfts/src/features/attributes.rs | 6 +++--- frame/nfts/src/features/metadata.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/nfts/src/features/attributes.rs b/frame/nfts/src/features/attributes.rs index 58399a2e8c56a..29e4de5e27328 100644 --- a/frame/nfts/src/features/attributes.rs +++ b/frame/nfts/src/features/attributes.rs @@ -386,7 +386,7 @@ impl, I: 'static> Pallet { /// # Errors /// /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the - /// provided attribute `key` is incorrectly formatted. + /// provided attribute `key` is too long. pub fn construct_attribute_key( key: Vec, ) -> Result, DispatchError> { @@ -398,7 +398,7 @@ impl, I: 'static> Pallet { /// # Errors /// /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the - /// provided `value` is incorrectly formatted. + /// provided `value` is too long. pub fn construct_attribute_value( value: Vec, ) -> Result, DispatchError> { @@ -410,7 +410,7 @@ impl, I: 'static> Pallet { /// # Errors /// /// This function returns an [`IncorrectData`](crate::Error::IncorrectData) error if the - /// provided pallet attribute is incorrectly formatted. + /// provided pallet attribute is too long. pub fn has_system_attribute( collection: &T::CollectionId, item: &T::ItemId, diff --git a/frame/nfts/src/features/metadata.rs b/frame/nfts/src/features/metadata.rs index ec1ff3a307a16..1493be1d8562e 100644 --- a/frame/nfts/src/features/metadata.rs +++ b/frame/nfts/src/features/metadata.rs @@ -213,7 +213,7 @@ impl, I: 'static> Pallet { /// # Errors /// /// This function returns an [`IncorrectMetadata`](crate::Error::IncorrectMetadata) dispatch - /// error if the provided metadata is incorrectly formatted. + /// error if the provided metadata is too long. pub fn construct_metadata( metadata: Vec, ) -> Result, DispatchError> {