diff --git a/substrate/frame/nfts/src/common_functions.rs b/substrate/frame/nfts/src/common_functions.rs index 694ebdcd12a7..c611824524ba 100644 --- a/substrate/frame/nfts/src/common_functions.rs +++ b/substrate/frame/nfts/src/common_functions.rs @@ -62,29 +62,29 @@ impl, I: 'static> Pallet { } /// Returns item depositor - pub fn item_depositor(collection: T::CollectionId, item: T::ItemId) -> Option { - Item::::get(collection, item).map(|i| i.deposit.account) - } + //pub fn item_depositor(collection: T::CollectionId, item: T::ItemId) -> Option { + // Item::::get(collection, item).map(|i| i.deposit.account) + //} /// Returns item deposit amount - pub fn item_deposit(collection: T::CollectionId, item: T::ItemId) -> Option>{ - Item::::get(collection, item).map(|i| i.deposit.amount) - } + //pub fn item_deposit(collection: T::CollectionId, item: T::ItemId) -> Option>{ + // Item::::get(collection, item).map(|i| i.deposit.amount) + //} /// Returns collection deposit - pub fn deposit(collection: T::CollectionId) -> Option>{ - Collection::::get(collection).map(|i| i.owner_deposit) - } + //pub fn deposit(collection: T::CollectionId) -> Option>{ + // Collection::::get(collection).map(|i| i.owner_deposit) + //} /// Returns collection data - pub fn collection_data(collection: T::CollectionId) -> Option>::StringLimit>> { - CollectionMetadataOf::::get(collection).map(|i| i.data) - } + //pub fn collection_data(collection: T::CollectionId) -> Option>::StringLimit>> { + // CollectionMetadataOf::::get(collection).map(|i| i.data) + //} /// Returns item data - pub fn item_data(collection: T::CollectionId, item: T::ItemId) -> Option>::StringLimit>> { - ItemMetadataOf::::get(collection, item).map(|i| i.data) - } + //pub fn item_data(collection: T::CollectionId, item: T::ItemId) -> Option>::StringLimit>> { + // ItemMetadataOf::::get(collection, item).map(|i| i.data) + //} pub(crate) fn set_next_collection_id(collection: T::CollectionId) { let next_id = collection.increment(); diff --git a/substrate/frame/nfts/src/types.rs b/substrate/frame/nfts/src/types.rs index 60d7c639c88c..9b58340ac937 100644 --- a/substrate/frame/nfts/src/types.rs +++ b/substrate/frame/nfts/src/types.rs @@ -31,49 +31,49 @@ 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 = +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 +81,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 +92,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 +143,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 +168,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 +182,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 /// hash-addressable global publication system such as IPFS. - pub(super) data: BoundedVec, + pub data: BoundedVec, } /// Information about the tip. @@ -206,31 +206,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/templates/parachain/pallets/xcnft/src/lib.rs b/templates/parachain/pallets/xcnft/src/lib.rs index b3c7afe168ca..b6af5963b6af 100644 --- a/templates/parachain/pallets/xcnft/src/lib.rs +++ b/templates/parachain/pallets/xcnft/src/lib.rs @@ -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: >::XcNftCall::from(Call::< T, @@ -593,9 +593,8 @@ use frame_system::pallet_prelude::*; if ReceivedCollections::::contains_key(&origin_collection) { ReceivedCollections::::remove(&origin_collection); } - - //Burning the collection - if let Some(col_deposit) = pallet_nfts::Pallet::::deposit(origin_collection) { + + if let Some(col_deposit) = pallet_nfts::Collection::::get(origin_collection).map(|i| i.owner_deposit) { T::Currency::unreserve(&who.clone(), col_deposit); } @@ -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::::contains_key(&origin_collection){ - collection_metadata = pallet_nfts::Pallet::::collection_data(origin_collection); + collection_metadata = Some(pallet_nfts::CollectionMetadataOf::::get(origin_collection).unwrap().data); } if collection_metadata.is_none() { @@ -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::::contains_key(&origin_collection, item_id) { - let item_details = pallet_nfts::Pallet::::item_data(origin_collection, item_id).unwrap(); + let item_details = pallet_nfts::ItemMetadataOf::::get(origin_collection, item_id).unwrap().data; nft_metadata.push((item_id,item_details)); }else{ //Add empty metadata @@ -759,7 +758,7 @@ use frame_system::pallet_prelude::*; let _ = pallet_nfts::Pallet::::burn(origin.clone(), origin_collection.clone(), item_id); } //Burning the collection - if let Some(col_deposit) = pallet_nfts::Pallet::::deposit(origin_collection) { + if let col_deposit = pallet_nfts::Collection::::get(origin_collection).unwrap().owner_deposit { T::Currency::unreserve(&who.clone(), col_deposit); } @@ -897,7 +896,7 @@ use frame_system::pallet_prelude::*; //Get the collection metadata let mut collection_metadata = Some(BoundedVec::new()); if pallet_nfts::CollectionMetadataOf::::contains_key(proposal.collection_id.clone()){ - collection_metadata = pallet_nfts::Pallet::::collection_data(proposal.collection_id.clone()); + collection_metadata = Some(pallet_nfts::CollectionMetadataOf::::get(proposal.collection_id.clone()).unwrap().data); } //Get NFT metadata @@ -925,7 +924,7 @@ use frame_system::pallet_prelude::*; let nft_owner = pallet_nfts::Pallet::::owner(proposal.collection_id.clone(), item_id).unwrap(); let unlooked_recipient = T::Lookup::unlookup(nft_owner.clone()); if pallet_nfts::ItemMetadataOf::::contains_key(proposal.collection_id.clone(), item_id) { - let item_details = pallet_nfts::Pallet::::item_data(proposal.collection_id.clone(), item_id).unwrap(); + let item_details = pallet_nfts::ItemMetadataOf::::get(proposal.collection_id.clone(), item_id).unwrap().data; nft_metadata.push((item_id,unlooked_recipient.clone(), item_details)); }else{ //Add empty metadata @@ -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::::item_depositor(proposal.collection_id.clone(), item_id) { - if let Some(deposit_amount) = pallet_nfts::Pallet::::item_deposit(proposal.collection_id.clone(), item_id) { + if let Some(depositor_account) = pallet_nfts::Item::::get(proposal.collection_id.clone(), item_id).map(|i| i.deposit.account) { + if let Some(deposit_amount) = pallet_nfts::Item::::get(proposal.collection_id.clone(), item_id).map(|i| i.deposit.amount) { T::Currency::unreserve(&depositor_account, deposit_amount); } } @@ -1008,7 +1007,7 @@ use frame_system::pallet_prelude::*; //Retrieve the collection details // Unreserve the funds - if let Some(col_deposit) = pallet_nfts::Pallet::::deposit(proposal.collection_id.clone()) { + if let Some(col_deposit) = pallet_nfts::Collection::::get(proposal.collection_id.clone()).map(|i| i.owner_deposit) { T::Currency::unreserve(&who.clone(), col_deposit); } @@ -1068,7 +1067,7 @@ use frame_system::pallet_prelude::*; let mut metadata = None; //Get Item data if pallet_nfts::ItemMetadataOf::::contains_key(&origin_collection, &origin_asset) { - metadata = pallet_nfts::Pallet::::item_data(origin_collection.clone(), origin_asset.clone()); + metadata = pallet_nfts::ItemMetadataOf::::get(origin_collection.clone(), origin_asset.clone()).map(|i| i.data); } else { metadata = Some(BoundedVec::new()); @@ -1206,7 +1205,7 @@ use frame_system::pallet_prelude::*; //Get the asset metadata let mut metadata = None; if pallet_nfts::ItemMetadataOf::::contains_key(current_collection.clone(), current_asset.clone()) { - metadata = pallet_nfts::Pallet::::item_data(current_collection.clone(), current_asset.clone()); + metadata = pallet_nfts::ItemMetadataOf::::get(current_collection.clone(), current_asset.clone()).map(|i| i.data); } else{ metadata = Some(BoundedVec::new());