Skip to content

Commit

Permalink
[pallet-nfts, pallet_uniques] - Expose private structs (#6087)
Browse files Browse the repository at this point in the history
# 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.
<img width="468" alt="screen1"
src="https://github.com/user-attachments/assets/f31f60b5-390c-4497-b46b-59dd561204ae">
<img width="664" alt="screen2"
src="https://github.com/user-attachments/assets/7e2aa71c-3bc4-49a9-8afc-47d4f45f4359">
<img width="598" alt="screen3"
src="https://github.com/user-attachments/assets/10f4e427-858f-460d-8644-f5750494edb0">



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 <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
dudo50 and bkontur authored Oct 21, 2024
1 parent ee803b7 commit 03f1d2d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 61 deletions.
12 changes: 12 additions & 0 deletions prdoc/pr_6087.prdoc
Original file line number Diff line number Diff line change
@@ -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
77 changes: 38 additions & 39 deletions substrate/frame/nfts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,56 @@ 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<T, I = ()> =
pub type DepositBalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
/// A type alias representing the details of a collection.
pub(super) type CollectionDetailsFor<T, I> =
pub type CollectionDetailsFor<T, I> =
CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
/// A type alias for keeping track of approvals used by a single item.
pub(super) type ApprovalsOf<T, I = ()> = BoundedBTreeMap<
pub type ApprovalsOf<T, I = ()> = BoundedBTreeMap<
<T as SystemConfig>::AccountId,
Option<BlockNumberFor<T>>,
<T as Config<I>>::ApprovalsLimit,
>;
/// A type alias for keeping track of approvals for an item's attributes.
pub(super) type ItemAttributesApprovals<T, I = ()> =
pub type ItemAttributesApprovals<T, I = ()> =
BoundedBTreeSet<<T as SystemConfig>::AccountId, <T as Config<I>>::ItemAttributesApprovalsLimit>;
/// A type that holds the deposit for a single item.
pub(super) type ItemDepositOf<T, I> =
ItemDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
pub type ItemDepositOf<T, I> = ItemDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
/// A type that holds the deposit amount for an item's attribute.
pub(super) type AttributeDepositOf<T, I> =
pub type AttributeDepositOf<T, I> =
AttributeDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
/// A type that holds the deposit amount for an item's metadata.
pub(super) type ItemMetadataDepositOf<T, I> =
pub type ItemMetadataDepositOf<T, I> =
ItemMetadataDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
/// A type that holds the details of a single item.
pub(super) type ItemDetailsFor<T, I> =
pub type ItemDetailsFor<T, I> =
ItemDetails<<T as SystemConfig>::AccountId, ItemDepositOf<T, I>, ApprovalsOf<T, I>>;
/// A type alias for an accounts balance.
pub(super) type BalanceOf<T, I = ()> =
pub type BalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
/// A type alias to represent the price of an item.
pub(super) type ItemPrice<T, I = ()> = BalanceOf<T, I>;
pub type ItemPrice<T, I = ()> = BalanceOf<T, I>;
/// A type alias for the tips held by a single item.
pub(super) type ItemTipOf<T, I = ()> = ItemTip<
pub type ItemTipOf<T, I = ()> = ItemTip<
<T as Config<I>>::CollectionId,
<T as Config<I>>::ItemId,
<T as SystemConfig>::AccountId,
BalanceOf<T, I>,
>;
/// A type alias for the settings configuration of a collection.
pub(super) type CollectionConfigFor<T, I = ()> =
pub type CollectionConfigFor<T, I = ()> =
CollectionConfig<BalanceOf<T, I>, BlockNumberFor<T>, <T as Config<I>>::CollectionId>;
/// A type alias for the pre-signed minting configuration for a specified collection.
pub(super) type PreSignedMintOf<T, I = ()> = PreSignedMint<
pub type PreSignedMintOf<T, I = ()> = PreSignedMint<
<T as Config<I>>::CollectionId,
<T as Config<I>>::ItemId,
<T as SystemConfig>::AccountId,
BlockNumberFor<T>,
BalanceOf<T, I>,
>;
/// A type alias for the pre-signed minting configuration on the attribute level of an item.
pub(super) type PreSignedAttributesOf<T, I = ()> = PreSignedAttributes<
pub type PreSignedAttributesOf<T, I = ()> = PreSignedAttributes<
<T as Config<I>>::CollectionId,
<T as Config<I>>::ItemId,
<T as SystemConfig>::AccountId,
Expand All @@ -92,18 +91,18 @@ pub(super) type PreSignedAttributesOf<T, I = ()> = PreSignedAttributes<
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails<AccountId, DepositBalance> {
/// 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.
Expand Down Expand Up @@ -143,21 +142,21 @@ pub struct MintWitness<ItemId, Balance> {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct ItemDetails<AccountId, Deposit, Approvals> {
/// 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<DepositBalance, AccountId> {
/// 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.
Expand All @@ -168,11 +167,11 @@ pub struct CollectionMetadata<Deposit, StringLimit: Get<u32>> {
/// 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<u8, StringLimit>,
pub data: BoundedVec<u8, StringLimit>,
}

/// Information about the item's metadata.
Expand All @@ -182,11 +181,11 @@ pub struct ItemMetadata<Deposit, StringLimit: Get<u32>> {
/// 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<u8, StringLimit>,
pub data: BoundedVec<u8, StringLimit>,
}

/// Information about the tip.
Expand All @@ -206,31 +205,31 @@ pub struct ItemTip<CollectionId, ItemId, AccountId, Amount> {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct PendingSwap<CollectionId, ItemId, ItemPriceWithDirection, Deadline> {
/// 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<ItemId>,
pub desired_item: Option<ItemId>,
/// A price for the desired `item` with the direction.
pub(super) price: Option<ItemPriceWithDirection>,
pub price: Option<ItemPriceWithDirection>,
/// 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<DepositBalance, AccountId> {
/// A depositor account.
pub(super) account: Option<AccountId>,
pub account: Option<AccountId>,
/// 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<DepositBalance, AccountId> {
/// A depositor account, None means the deposit is collection's owner.
pub(super) account: Option<AccountId>,
pub account: Option<AccountId>,
/// An amount that gets reserved.
pub(super) amount: DepositBalance,
pub amount: DepositBalance,
}

/// Specifies whether the tokens will be sent or received.
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/uniques/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::storage_prefix = "ClassMetadataOf"]
/// Metadata of a collection.
pub(super) type CollectionMetadataOf<T: Config<I>, I: 'static = ()> = StorageMap<
pub type CollectionMetadataOf<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Blake2_128Concat,
T::CollectionId,
Expand All @@ -234,7 +234,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::storage_prefix = "InstanceMetadataOf"]
/// Metadata of an item.
pub(super) type ItemMetadataOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
pub type ItemMetadataOf<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
_,
Blake2_128Concat,
T::CollectionId,
Expand Down
40 changes: 20 additions & 20 deletions substrate/frame/uniques/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ pub(super) type ItemPrice<T, I = ()> =
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct CollectionDetails<AccountId, DepositBalance> {
/// 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.
Expand Down Expand Up @@ -90,14 +90,14 @@ impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct ItemDetails<AccountId, DepositBalance> {
/// 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<AccountId>,
pub approved: Option<AccountId>,
/// 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)]
Expand All @@ -107,13 +107,13 @@ pub struct CollectionMetadata<DepositBalance, StringLimit: Get<u32>> {
/// 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<u8, StringLimit>,
pub data: BoundedVec<u8, StringLimit>,
/// 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)]
Expand All @@ -123,11 +123,11 @@ pub struct ItemMetadata<DepositBalance, StringLimit: Get<u32>> {
/// 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<u8, StringLimit>,
pub data: BoundedVec<u8, StringLimit>,
/// Whether the item metadata may be changed by a non Force origin.
pub(super) is_frozen: bool,
pub is_frozen: bool,
}

0 comments on commit 03f1d2d

Please sign in to comment.