--- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -967,7 +967,7 @@ let target_collection = >::get(collection_id); - Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?; + Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner, 1)?; Self::validate_create_item_args(&target_collection, &data)?; Self::create_item_no_validation(collection_id, owner, data)?; @@ -1003,7 +1003,7 @@ Self::collection_exists(collection_id)?; let target_collection = >::get(collection_id); - Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner)?; + Self::can_create_items_in_collection(collection_id, &target_collection, &sender, &owner, items_data.len() as u32)?; for data in &items_data { Self::validate_create_item_args(&target_collection, data)?; @@ -1640,13 +1640,17 @@ Ok(()) } - fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType, sender: &T::AccountId, owner: &T::AccountId) -> DispatchResult { + fn can_create_items_in_collection(collection_id: CollectionId, collection: &CollectionType, sender: &T::AccountId, owner: &T::AccountId, amount: u32) -> DispatchResult { // check token limit and account token limit - let total_items: u32 = ItemListIndex::get(collection_id); - let account_items: u32 = >::get(collection_id, owner).len() as u32; - ensure!(collection.limits.token_limit > total_items, Error::::CollectionTokenLimitExceeded); - ensure!(collection.limits.account_token_ownership_limit > account_items, Error::::AccountTokenLimitExceeded); + let total_items: u32 = ItemListIndex::get(collection_id) + .checked_add(amount) + .ok_or(Error::::CollectionTokenLimitExceeded)?; + let account_items: u32 = (>::get(collection_id, owner).len() as u32) + .checked_add(amount) + .ok_or(Error::::AccountTokenLimitExceeded)?; + ensure!(collection.limits.token_limit >= total_items, Error::::CollectionTokenLimitExceeded); + ensure!(collection.limits.account_token_ownership_limit >= account_items, Error::::AccountTokenLimitExceeded); if !Self::is_owner_or_admin_permissions(collection_id, sender.clone()) { ensure!(collection.mint_mode == true, Error::::PublicMintingNotAllowed);