Skip to content

Commit

Permalink
Rework types, to exposed structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Oct 16, 2024
1 parent 4ddb371 commit 10228e3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 66 deletions.
30 changes: 15 additions & 15 deletions substrate/frame/nfts/src/common_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,29 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

/// Returns item depositor
pub fn item_depositor(collection: T::CollectionId, item: T::ItemId) -> Option<T::AccountId> {
Item::<T, I>::get(collection, item).map(|i| i.deposit.account)
}
//pub fn item_depositor(collection: T::CollectionId, item: T::ItemId) -> Option<T::AccountId> {
// Item::<T, I>::get(collection, item).map(|i| i.deposit.account)
//}

/// Returns item deposit amount
pub fn item_deposit(collection: T::CollectionId, item: T::ItemId) -> Option<DepositBalanceOf<T, I>>{
Item::<T, I>::get(collection, item).map(|i| i.deposit.amount)
}
//pub fn item_deposit(collection: T::CollectionId, item: T::ItemId) -> Option<DepositBalanceOf<T, I>>{
// Item::<T, I>::get(collection, item).map(|i| i.deposit.amount)
//}

/// Returns collection deposit
pub fn deposit(collection: T::CollectionId) -> Option<DepositBalanceOf<T, I>>{
Collection::<T, I>::get(collection).map(|i| i.owner_deposit)
}
//pub fn deposit(collection: T::CollectionId) -> Option<DepositBalanceOf<T, I>>{
// Collection::<T, I>::get(collection).map(|i| i.owner_deposit)
//}

/// Returns collection data
pub fn collection_data(collection: T::CollectionId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
CollectionMetadataOf::<T, I>::get(collection).map(|i| i.data)
}
//pub fn collection_data(collection: T::CollectionId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
// CollectionMetadataOf::<T, I>::get(collection).map(|i| i.data)
//}

/// Returns item data
pub fn item_data(collection: T::CollectionId, item: T::ItemId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
ItemMetadataOf::<T, I>::get(collection, item).map(|i| i.data)
}
//pub fn item_data(collection: T::CollectionId, item: T::ItemId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
// ItemMetadataOf::<T, I>::get(collection, item).map(|i| i.data)
//}

pub(crate) fn set_next_collection_id(collection: T::CollectionId) {
let next_id = collection.increment();
Expand Down
74 changes: 37 additions & 37 deletions substrate/frame/nfts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,57 @@ 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> =
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 +92,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 +143,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 +168,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 +182,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
/// 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 +206,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
27 changes: 13 additions & 14 deletions templates/parachain/pallets/xcnft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ use frame_system::pallet_prelude::*;
Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::SovereignAccount,
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(1_000_000_000, 64 * 1024),
call: <T as Config<I>>::XcNftCall::from(Call::<
T,
Expand All @@ -593,9 +593,8 @@ use frame_system::pallet_prelude::*;
if ReceivedCollections::<T, I>::contains_key(&origin_collection) {
ReceivedCollections::<T, I>::remove(&origin_collection);
}

//Burning the collection
if let Some(col_deposit) = pallet_nfts::Pallet::<T, I>::deposit(origin_collection) {

if let Some(col_deposit) = pallet_nfts::Collection::<T, I>::get(origin_collection).map(|i| i.owner_deposit) {
T::Currency::unreserve(&who.clone(), col_deposit);
}

Expand Down Expand Up @@ -705,7 +704,7 @@ use frame_system::pallet_prelude::*;
//First check if collection contains any metadata
let mut collection_metadata = None;
if pallet_nfts::CollectionMetadataOf::<T, I>::contains_key(&origin_collection){
collection_metadata = pallet_nfts::Pallet::<T, I>::collection_data(origin_collection);
collection_metadata = Some(pallet_nfts::CollectionMetadataOf::<T, I>::get(origin_collection).unwrap().data);
}

if collection_metadata.is_none() {
Expand All @@ -716,7 +715,7 @@ use frame_system::pallet_prelude::*;
let mut nft_metadata = Vec::new();
for item_id in items.clone() {
if pallet_nfts::ItemMetadataOf::<T, I>::contains_key(&origin_collection, item_id) {
let item_details = pallet_nfts::Pallet::<T, I>::item_data(origin_collection, item_id).unwrap();
let item_details = pallet_nfts::ItemMetadataOf::<T, I>::get(origin_collection, item_id).unwrap().data;
nft_metadata.push((item_id,item_details));
}else{
//Add empty metadata
Expand Down Expand Up @@ -759,7 +758,7 @@ use frame_system::pallet_prelude::*;
let _ = pallet_nfts::Pallet::<T, I>::burn(origin.clone(), origin_collection.clone(), item_id);
}
//Burning the collection
if let Some(col_deposit) = pallet_nfts::Pallet::<T, I>::deposit(origin_collection) {
if let col_deposit = pallet_nfts::Collection::<T, I>::get(origin_collection).unwrap().owner_deposit {
T::Currency::unreserve(&who.clone(), col_deposit);
}

Expand Down Expand Up @@ -897,7 +896,7 @@ use frame_system::pallet_prelude::*;
//Get the collection metadata
let mut collection_metadata = Some(BoundedVec::new());
if pallet_nfts::CollectionMetadataOf::<T, I>::contains_key(proposal.collection_id.clone()){
collection_metadata = pallet_nfts::Pallet::<T, I>::collection_data(proposal.collection_id.clone());
collection_metadata = Some(pallet_nfts::CollectionMetadataOf::<T, I>::get(proposal.collection_id.clone()).unwrap().data);
}

//Get NFT metadata
Expand Down Expand Up @@ -925,7 +924,7 @@ use frame_system::pallet_prelude::*;
let nft_owner = pallet_nfts::Pallet::<T, I>::owner(proposal.collection_id.clone(), item_id).unwrap();
let unlooked_recipient = T::Lookup::unlookup(nft_owner.clone());
if pallet_nfts::ItemMetadataOf::<T, I>::contains_key(proposal.collection_id.clone(), item_id) {
let item_details = pallet_nfts::Pallet::<T, I>::item_data(proposal.collection_id.clone(), item_id).unwrap();
let item_details = pallet_nfts::ItemMetadataOf::<T, I>::get(proposal.collection_id.clone(), item_id).unwrap().data;
nft_metadata.push((item_id,unlooked_recipient.clone(), item_details));
}else{
//Add empty metadata
Expand Down Expand Up @@ -972,8 +971,8 @@ use frame_system::pallet_prelude::*;
for item_id in items.clone() {

//Unreserve the funds of person who created NFT
if let Some(depositor_account) = pallet_nfts::Pallet::<T, I>::item_depositor(proposal.collection_id.clone(), item_id) {
if let Some(deposit_amount) = pallet_nfts::Pallet::<T, I>::item_deposit(proposal.collection_id.clone(), item_id) {
if let Some(depositor_account) = pallet_nfts::Item::<T, I>::get(proposal.collection_id.clone(), item_id).map(|i| i.deposit.account) {
if let Some(deposit_amount) = pallet_nfts::Item::<T, I>::get(proposal.collection_id.clone(), item_id).map(|i| i.deposit.amount) {
T::Currency::unreserve(&depositor_account, deposit_amount);
}
}
Expand Down Expand Up @@ -1008,7 +1007,7 @@ use frame_system::pallet_prelude::*;
//Retrieve the collection details

// Unreserve the funds
if let Some(col_deposit) = pallet_nfts::Pallet::<T, I>::deposit(proposal.collection_id.clone()) {
if let Some(col_deposit) = pallet_nfts::Collection::<T, I>::get(proposal.collection_id.clone()).map(|i| i.owner_deposit) {
T::Currency::unreserve(&who.clone(), col_deposit);
}

Expand Down Expand Up @@ -1068,7 +1067,7 @@ use frame_system::pallet_prelude::*;
let mut metadata = None;
//Get Item data
if pallet_nfts::ItemMetadataOf::<T, I>::contains_key(&origin_collection, &origin_asset) {
metadata = pallet_nfts::Pallet::<T, I>::item_data(origin_collection.clone(), origin_asset.clone());
metadata = pallet_nfts::ItemMetadataOf::<T, I>::get(origin_collection.clone(), origin_asset.clone()).map(|i| i.data);
}
else {
metadata = Some(BoundedVec::new());
Expand Down Expand Up @@ -1206,7 +1205,7 @@ use frame_system::pallet_prelude::*;
//Get the asset metadata
let mut metadata = None;
if pallet_nfts::ItemMetadataOf::<T, I>::contains_key(current_collection.clone(), current_asset.clone()) {
metadata = pallet_nfts::Pallet::<T, I>::item_data(current_collection.clone(), current_asset.clone());
metadata = pallet_nfts::ItemMetadataOf::<T, I>::get(current_collection.clone(), current_asset.clone()).map(|i| i.data);
}
else{
metadata = Some(BoundedVec::new());
Expand Down

0 comments on commit 10228e3

Please sign in to comment.