From 03f1d2d646c35239405514cbb73bd376b85636cd Mon Sep 17 00:00:00 2001
From: Dusan Morhac <55763425+dudo50@users.noreply.github.com>
Date: Mon, 21 Oct 2024 23:40:00 +0200
Subject: [PATCH] [pallet-nfts, pallet_uniques] - Expose private structs
(#6087)
# Description
This PR exposes pallet_nfts and pallet_uniques structs, so other pallets
can access storage to use it for extending nft functionalities.
In pallet uniques it also exposes collection and asset metadata storage
as they are private.
## Integration
This integration allows nfts and uniques extension pallets to use then
private - now public structs to retrieve and parse storage from
pallet_nfts. We are building cross-chain NFT pallet and in order to
transfer collection that houses multiple NFT owners we need to manually
remove NFTs and Collections from storage without signers. We would also
like to refund deposits on origin chain and we were unable to as struct
data was private.
We have built cross-chain pallet that allows to send nfts or collections
between two pallets in abstract way without having to look which pallet
parachain (If nfts or uniques) implements.
## Review Notes
Code exposes private structs to public structs. No breaking change.
Build runs fine, tests are also ok.
PR is tied with following issue:
Closes #5959
# Checklist
* [x] My PR includes a detailed description as outlined in the
"Description" and its two subsections above.
* [x] My PR follows the [labeling requirements](
https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
) of this project (at minimum one label for `T` required)
* External contributors: ask maintainers to put the right label on your
PR.
* [ ] I have made corresponding changes to the documentation (if
applicable)
* [ ] I have added tests that prove my fix is effective or that my
feature works (if applicable)
---------
Co-authored-by: Branislav Kontur
Co-authored-by: command-bot <>
---
prdoc/pr_6087.prdoc | 12 +++++
substrate/frame/nfts/src/types.rs | 77 ++++++++++++++--------------
substrate/frame/uniques/src/lib.rs | 4 +-
substrate/frame/uniques/src/types.rs | 40 +++++++--------
4 files changed, 72 insertions(+), 61 deletions(-)
create mode 100644 prdoc/pr_6087.prdoc
diff --git a/prdoc/pr_6087.prdoc b/prdoc/pr_6087.prdoc
new file mode 100644
index 000000000000..db083ba645b9
--- /dev/null
+++ b/prdoc/pr_6087.prdoc
@@ -0,0 +1,12 @@
+title: Expose private structs in pallet_nfts and pallet_uniques.
+
+doc:
+ - audience: Runtime Dev
+ description: |
+ PR changes certain structs in pallet_nfts and pallet_uniques into public. It also changes 2 storages (collection & asset metadata) into public in pallet_uniques.
+
+crates:
+ - name: pallet-nfts
+ bump: patch
+ - name: pallet-uniques
+ bump: patch
diff --git a/substrate/frame/nfts/src/types.rs b/substrate/frame/nfts/src/types.rs
index 60d7c639c88c..d67fb404ea79 100644
--- a/substrate/frame/nfts/src/types.rs
+++ b/substrate/frame/nfts/src/types.rs
@@ -31,49 +31,48 @@ use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter};
/// A type alias for handling balance deposits.
-pub(super) type DepositBalanceOf =
+pub type DepositBalanceOf =
<>::Currency as Currency<::AccountId>>::Balance;
/// A type alias representing the details of a collection.
-pub(super) type CollectionDetailsFor =
+pub type CollectionDetailsFor =
CollectionDetails<::AccountId, DepositBalanceOf>;
/// A type alias for keeping track of approvals used by a single item.
-pub(super) type ApprovalsOf = BoundedBTreeMap<
+pub type ApprovalsOf = BoundedBTreeMap<
::AccountId,
Option>,
>::ApprovalsLimit,
>;
/// A type alias for keeping track of approvals for an item's attributes.
-pub(super) type ItemAttributesApprovals =
+pub type ItemAttributesApprovals =
BoundedBTreeSet<::AccountId, >::ItemAttributesApprovalsLimit>;
/// A type that holds the deposit for a single item.
-pub(super) type ItemDepositOf =
- ItemDeposit, ::AccountId>;
+pub type ItemDepositOf = ItemDeposit, ::AccountId>;
/// A type that holds the deposit amount for an item's attribute.
-pub(super) type AttributeDepositOf =
+pub type AttributeDepositOf =
AttributeDeposit, ::AccountId>;
/// A type that holds the deposit amount for an item's metadata.
-pub(super) type ItemMetadataDepositOf =
+pub type ItemMetadataDepositOf =
ItemMetadataDeposit, ::AccountId>;
/// A type that holds the details of a single item.
-pub(super) type ItemDetailsFor =
+pub type ItemDetailsFor =
ItemDetails<::AccountId, ItemDepositOf, ApprovalsOf>;
/// A type alias for an accounts balance.
-pub(super) type BalanceOf =
+pub type BalanceOf =
<>::Currency as Currency<::AccountId>>::Balance;
/// A type alias to represent the price of an item.
-pub(super) type ItemPrice = BalanceOf;
+pub type ItemPrice = BalanceOf;
/// A type alias for the tips held by a single item.
-pub(super) type ItemTipOf = ItemTip<
+pub type ItemTipOf = ItemTip<
>::CollectionId,
>::ItemId,
::AccountId,
BalanceOf,
>;
/// A type alias for the settings configuration of a collection.
-pub(super) type CollectionConfigFor =
+pub type CollectionConfigFor =
CollectionConfig, BlockNumberFor, >::CollectionId>;
/// A type alias for the pre-signed minting configuration for a specified collection.
-pub(super) type PreSignedMintOf = PreSignedMint<
+pub type PreSignedMintOf = PreSignedMint<
>::CollectionId,
>::ItemId,
::AccountId,
@@ -81,7 +80,7 @@ pub(super) type PreSignedMintOf = PreSignedMint<
BalanceOf,
>;
/// A type alias for the pre-signed minting configuration on the attribute level of an item.
-pub(super) type PreSignedAttributesOf = PreSignedAttributes<
+pub type PreSignedAttributesOf = PreSignedAttributes<
>::CollectionId,
>::ItemId,
::AccountId,
@@ -92,18 +91,18 @@ pub(super) type PreSignedAttributesOf = PreSignedAttributes<
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails {
/// Collection's owner.
- pub(super) owner: AccountId,
+ pub owner: AccountId,
/// The total balance deposited by the owner for all the storage data associated with this
/// collection. Used by `destroy`.
- pub(super) owner_deposit: DepositBalance,
+ pub owner_deposit: DepositBalance,
/// The total number of outstanding items of this collection.
- pub(super) items: u32,
+ pub items: u32,
/// The total number of outstanding item metadata of this collection.
- pub(super) item_metadatas: u32,
+ pub item_metadatas: u32,
/// The total number of outstanding item configs of this collection.
- pub(super) item_configs: u32,
+ pub item_configs: u32,
/// The total number of attributes for this collection.
- pub(super) attributes: u32,
+ pub attributes: u32,
}
/// Witness data for the destroy transactions.
@@ -143,21 +142,21 @@ pub struct MintWitness {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct ItemDetails {
/// The owner of this item.
- pub(super) owner: AccountId,
+ pub owner: AccountId,
/// The approved transferrer of this item, if one is set.
- pub(super) approvals: Approvals,
+ pub approvals: Approvals,
/// The amount held in the pallet's default account for this item. Free-hold items will have
/// this as zero.
- pub(super) deposit: Deposit,
+ pub deposit: Deposit,
}
/// Information about the reserved item deposit.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct ItemDeposit {
/// A depositor account.
- pub(super) account: AccountId,
+ pub account: AccountId,
/// An amount that gets reserved.
- pub(super) amount: DepositBalance,
+ pub amount: DepositBalance,
}
/// Information about the collection's metadata.
@@ -168,11 +167,11 @@ pub struct CollectionMetadata> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
- pub(super) deposit: Deposit,
+ pub deposit: Deposit,
/// General information concerning this collection. Limited in length by `StringLimit`. This
/// will generally be either a JSON dump or the hash of some JSON which can be found on a
/// hash-addressable global publication system such as IPFS.
- pub(super) data: BoundedVec,
+ pub data: BoundedVec,
}
/// Information about the item's metadata.
@@ -182,11 +181,11 @@ pub struct ItemMetadata> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
- pub(super) deposit: Deposit,
+ pub deposit: Deposit,
/// General information concerning this item. Limited in length by `StringLimit`. This will
- /// generally be either a JSON dump or the hash of some JSON which can be found on a
+ /// generally be either a JSON dump or the hash of some JSON which can be found on
/// hash-addressable global publication system such as IPFS.
- pub(super) data: BoundedVec,
+ pub data: BoundedVec,
}
/// Information about the tip.
@@ -206,31 +205,31 @@ pub struct ItemTip {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct PendingSwap {
/// The collection that contains the item that the user wants to receive.
- pub(super) desired_collection: CollectionId,
+ pub desired_collection: CollectionId,
/// The item the user wants to receive.
- pub(super) desired_item: Option,
+ pub desired_item: Option,
/// A price for the desired `item` with the direction.
- pub(super) price: Option,
+ pub price: Option,
/// A deadline for the swap.
- pub(super) deadline: Deadline,
+ pub deadline: Deadline,
}
/// Information about the reserved attribute deposit.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct AttributeDeposit {
/// A depositor account.
- pub(super) account: Option,
+ pub account: Option,
/// An amount that gets reserved.
- pub(super) amount: DepositBalance,
+ pub amount: DepositBalance,
}
/// Information about the reserved item's metadata deposit.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct ItemMetadataDeposit {
/// A depositor account, None means the deposit is collection's owner.
- pub(super) account: Option,
+ pub account: Option,
/// An amount that gets reserved.
- pub(super) amount: DepositBalance,
+ pub amount: DepositBalance,
}
/// Specifies whether the tokens will be sent or received.
diff --git a/substrate/frame/uniques/src/lib.rs b/substrate/frame/uniques/src/lib.rs
index dc27c3356234..84f122c08bb7 100644
--- a/substrate/frame/uniques/src/lib.rs
+++ b/substrate/frame/uniques/src/lib.rs
@@ -223,7 +223,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::storage_prefix = "ClassMetadataOf"]
/// Metadata of a collection.
- pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap<
+ pub type CollectionMetadataOf, I: 'static = ()> = StorageMap<
_,
Blake2_128Concat,
T::CollectionId,
@@ -234,7 +234,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::storage_prefix = "InstanceMetadataOf"]
/// Metadata of an item.
- pub(super) type ItemMetadataOf, I: 'static = ()> = StorageDoubleMap<
+ pub type ItemMetadataOf, I: 'static = ()> = StorageDoubleMap<
_,
Blake2_128Concat,
T::CollectionId,
diff --git a/substrate/frame/uniques/src/types.rs b/substrate/frame/uniques/src/types.rs
index a2e804f245f7..e2e170c72f21 100644
--- a/substrate/frame/uniques/src/types.rs
+++ b/substrate/frame/uniques/src/types.rs
@@ -40,26 +40,26 @@ pub(super) type ItemPrice =
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails {
/// Can change `owner`, `issuer`, `freezer` and `admin` accounts.
- pub(super) owner: AccountId,
+ pub owner: AccountId,
/// Can mint tokens.
- pub(super) issuer: AccountId,
+ pub issuer: AccountId,
/// Can thaw tokens, force transfers and burn tokens from any account.
- pub(super) admin: AccountId,
+ pub admin: AccountId,
/// Can freeze tokens.
- pub(super) freezer: AccountId,
+ pub freezer: AccountId,
/// The total balance deposited for the all storage associated with this collection.
/// Used by `destroy`.
- pub(super) total_deposit: DepositBalance,
+ pub total_deposit: DepositBalance,
/// If `true`, then no deposit is needed to hold items of this collection.
- pub(super) free_holding: bool,
+ pub free_holding: bool,
/// The total number of outstanding items of this collection.
- pub(super) items: u32,
+ pub items: u32,
/// The total number of outstanding item metadata of this collection.
- pub(super) item_metadatas: u32,
+ pub item_metadatas: u32,
/// The total number of attributes for this collection.
- pub(super) attributes: u32,
+ pub attributes: u32,
/// Whether the collection is frozen for non-admin transfers.
- pub(super) is_frozen: bool,
+ pub is_frozen: bool,
}
/// Witness data for the destroy transactions.
@@ -90,14 +90,14 @@ impl CollectionDetails {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct ItemDetails {
/// The owner of this item.
- pub(super) owner: AccountId,
+ pub owner: AccountId,
/// The approved transferrer of this item, if one is set.
- pub(super) approved: Option,
+ pub approved: Option,
/// Whether the item can be transferred or not.
- pub(super) is_frozen: bool,
+ pub is_frozen: bool,
/// The amount held in the pallet's default account for this item. Free-hold items will have
/// this as zero.
- pub(super) deposit: DepositBalance,
+ pub deposit: DepositBalance,
}
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
@@ -107,13 +107,13 @@ pub struct CollectionMetadata> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
- pub(super) deposit: DepositBalance,
+ pub deposit: DepositBalance,
/// General information concerning this collection. Limited in length by `StringLimit`. This
/// will generally be either a JSON dump or the hash of some JSON which can be found on a
/// hash-addressable global publication system such as IPFS.
- pub(super) data: BoundedVec,
+ pub data: BoundedVec,
/// Whether the collection's metadata may be changed by a non Force origin.
- pub(super) is_frozen: bool,
+ pub is_frozen: bool,
}
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
@@ -123,11 +123,11 @@ pub struct ItemMetadata> {
/// The balance deposited for this metadata.
///
/// This pays for the data stored in this struct.
- pub(super) deposit: DepositBalance,
+ pub deposit: DepositBalance,
/// General information concerning this item. Limited in length by `StringLimit`. This will
/// generally be either a JSON dump or the hash of some JSON which can be found on a
/// hash-addressable global publication system such as IPFS.
- pub(super) data: BoundedVec,
+ pub data: BoundedVec,
/// Whether the item metadata may be changed by a non Force origin.
- pub(super) is_frozen: bool,
+ pub is_frozen: bool,
}