--- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -331,6 +331,8 @@ MustBeTokenOwner, /// No permission to perform action NoPermission, + /// Destroying only empty collections is allowed + CantDestroyNotEmptyCollection, /// Collection is not in mint mode. PublicMintingNotAllowed, /// Address is not in allow list. --- a/pallets/fungible/src/lib.rs +++ b/pallets/fungible/src/lib.rs @@ -145,6 +145,10 @@ ) -> DispatchResult { let id = collection.id; + if Self::collection_has_tokens(id) { + return Err(>::CantDestroyNotEmptyCollection.into()); + } + // ========= PalletCommon::destroy_collection(collection.0, sender)?; @@ -155,6 +159,10 @@ Ok(()) } + fn collection_has_tokens(collection_id: CollectionId) -> bool { + >::get(collection_id) != 0 + } + pub fn burn( collection: &FungibleHandle, owner: &T::CrossAccountId, --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -79,8 +79,6 @@ NonfungibleItemsHaveNoAmount, /// Unable to burn NFT with children CantBurnNftWithChildren, - /// Unable to burn a collection containing NFTs that have children - CantBurnCollectionWithNestedTokens } #[pallet::config] @@ -295,8 +293,8 @@ ) -> DispatchResult { let id = collection.id; - if Self::collection_has_nested_tokens(id) { - return Err(>::CantBurnCollectionWithNestedTokens.into()); + if Self::collection_has_tokens(id) { + return Err(>::CantDestroyNotEmptyCollection.into()); } // ========= @@ -972,8 +970,8 @@ ); } - fn collection_has_nested_tokens(collection_id: CollectionId) -> bool { - >::iter_prefix((collection_id,)).next().is_some() + fn collection_has_tokens(collection_id: CollectionId) -> bool { + >::iter_prefix((collection_id,)).next().is_some() } fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool { --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -210,6 +210,10 @@ ) -> DispatchResult { let id = collection.id; + if Self::collection_has_tokens(id) { + return Err(>::CantDestroyNotEmptyCollection.into()); + } + // ========= PalletCommon::destroy_collection(collection.0, sender)?; @@ -225,6 +229,10 @@ Ok(()) } + fn collection_has_tokens(collection_id: CollectionId) -> bool { + >::iter_prefix((collection_id,)).next().is_some() + } + pub fn burn_token(collection: &RefungibleHandle, token_id: TokenId) -> DispatchResult { let burnt = >::get(collection.id) .checked_add(1)