From 007511b3e6628c3eab3deacd4e9d850e88c2742d Mon Sep 17 00:00:00 2001 From: chexware Date: Tue, 9 Jul 2024 14:13:25 +0100 Subject: [PATCH 1/3] fix: disable owner check in update_class_total_issuance for pre-signed mints as it is already checked in do_mint_pre_signed --- pallets/nft/src/lib.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pallets/nft/src/lib.rs b/pallets/nft/src/lib.rs index ae1d8b15..7c20eb6d 100644 --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -545,7 +545,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; - Self::update_class_total_issuance(&sender, &class_id, 1u32)?; + Self::update_class_total_issuance(&sender, &class_id, 1u32, false)?; // Collect minting deposit let class_fund: T::AccountId = T::Treasury::get().into_account_truncating(); let deposit = T::AssetMintingFee::get().saturating_mul(Into::>::into(1u32)); @@ -1167,7 +1167,7 @@ impl Pallet { ); // Update class total issuance - Self::update_class_total_issuance(&sender, &class_id, quantity)?; + Self::update_class_total_issuance(&sender, &class_id, quantity, false)?; let class_fund: T::AccountId = T::Treasury::get().into_account_truncating(); let deposit = T::AssetMintingFee::get().saturating_mul(Into::>::into(quantity)); @@ -1212,6 +1212,7 @@ impl Pallet { metadata: NftMetadata, attributes: Attributes, is_locked: bool, + is_pre_signed_mint: bool, ) -> Result, DispatchError> { ensure!(!Self::is_collection_locked(&class_id), Error::::CollectionIsLocked); @@ -1221,7 +1222,7 @@ impl Pallet { ); // Update class total issuance - Self::update_class_total_issuance(&sender, &class_id, 1u32)?; + Self::update_class_total_issuance(&sender, &class_id, 1u32, is_pre_signed_mint)?; let class_fund: T::AccountId = T::Treasury::get().into_account_truncating(); let deposit = T::AssetMintingFee::get().saturating_mul(Into::>::into(1u32)); @@ -1301,7 +1302,9 @@ impl Pallet { )?; } - Self::do_mint_nft_with_token_id(&mint_to, &mint_to, class_id, token_id, metadata, attributes, false)?; + Self::do_mint_nft_with_token_id( + &mint_to, &mint_to, class_id, token_id, metadata, attributes, false, true, + )?; Ok(()) } @@ -1316,8 +1319,9 @@ impl Pallet { attributes: Attributes, is_locked: bool, ) -> Result<(ClassIdOf, TokenIdOf), DispatchError> { - let minted_token_id = - Self::do_mint_nft_with_token_id(&sender, &mint_to, class_id, token_id, metadata, attributes, is_locked)?; + let minted_token_id = Self::do_mint_nft_with_token_id( + &sender, &mint_to, class_id, token_id, metadata, attributes, is_locked, false, + )?; let nft_proxy_account: T::AccountId = T::PalletId::get().into_sub_account_truncating((class_id, &minted_token_id)); let proxy_deposit = >::deposit(1u32); @@ -1423,11 +1427,18 @@ impl Pallet { } /// Update total minted tokens for a class - fn update_class_total_issuance(sender: &T::AccountId, class_id: &ClassIdOf, quantity: u32) -> DispatchResult { + fn update_class_total_issuance( + sender: &T::AccountId, + class_id: &ClassIdOf, + quantity: u32, + is_signed_mint: bool, + ) -> DispatchResult { // update class total issuance Classes::::try_mutate(class_id, |class_info| -> DispatchResult { let info = class_info.as_mut().ok_or(Error::::ClassIdNotFound)?; - ensure!(info.owner == sender.clone(), Error::::NoPermission); + if !is_pre_signed_mint { + ensure!(info.owner == sender.clone(), Error::::NoPermission); + } match info.data.mint_limit { Some(l) => { ensure!( From e0a669142e28e175a910ab81f6d0ba6601cc43c6 Mon Sep 17 00:00:00 2001 From: chexware Date: Tue, 9 Jul 2024 14:19:34 +0100 Subject: [PATCH 2/3] fix: fixed build errors after changes --- pallets/nft/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/nft/src/lib.rs b/pallets/nft/src/lib.rs index 7c20eb6d..e7a109eb 100644 --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -1431,7 +1431,7 @@ impl Pallet { sender: &T::AccountId, class_id: &ClassIdOf, quantity: u32, - is_signed_mint: bool, + is_pre_signed_mint: bool, ) -> DispatchResult { // update class total issuance Classes::::try_mutate(class_id, |class_info| -> DispatchResult { @@ -1718,7 +1718,7 @@ impl NFTTrait> for Pallet { metadata: NftMetadata, attributes: Attributes, ) -> Result { - Self::do_mint_nft_with_token_id(sender, sender, class_id, Some(token_id), metadata, attributes, false) + Self::do_mint_nft_with_token_id(sender, sender, class_id, Some(token_id), metadata, attributes, false, false) } fn get_free_stackable_nft_balance(who: &T::AccountId, asset_id: &(Self::ClassId, Self::TokenId)) -> BalanceOf { From 5af2551f2cab8fb923784f8de1af3eadf19049c7 Mon Sep 17 00:00:00 2001 From: chexware Date: Tue, 9 Jul 2024 14:38:44 +0100 Subject: [PATCH 3/3] style: fixed formatting --- pallets/nft/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pallets/nft/src/lib.rs b/pallets/nft/src/lib.rs index e7a109eb..24f3f244 100644 --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -1718,7 +1718,16 @@ impl NFTTrait> for Pallet { metadata: NftMetadata, attributes: Attributes, ) -> Result { - Self::do_mint_nft_with_token_id(sender, sender, class_id, Some(token_id), metadata, attributes, false, false) + Self::do_mint_nft_with_token_id( + sender, + sender, + class_id, + Some(token_id), + metadata, + attributes, + false, + false, + ) } fn get_free_stackable_nft_balance(who: &T::AccountId, asset_id: &(Self::ClassId, Self::TokenId)) -> BalanceOf {