difftreelog
fix destroy only not empty collections
in: master
4 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- 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.
pallets/fungible/src/lib.rsdiffbeforeafterboth--- 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(<CommonError<T>>::CantDestroyNotEmptyCollection.into());
+ }
+
// =========
PalletCommon::destroy_collection(collection.0, sender)?;
@@ -155,6 +159,10 @@
Ok(())
}
+ fn collection_has_tokens(collection_id: CollectionId) -> bool {
+ <TotalSupply<T>>::get(collection_id) != 0
+ }
+
pub fn burn(
collection: &FungibleHandle<T>,
owner: &T::CrossAccountId,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth79 NonfungibleItemsHaveNoAmount,79 NonfungibleItemsHaveNoAmount,80 /// Unable to burn NFT with children80 /// Unable to burn NFT with children81 CantBurnNftWithChildren,81 CantBurnNftWithChildren,82 /// Unable to burn a collection containing NFTs that have children83 CantBurnCollectionWithNestedTokens84 }82 }858386 #[pallet::config]84 #[pallet::config]295 ) -> DispatchResult {293 ) -> DispatchResult {296 let id = collection.id;294 let id = collection.id;297295298 if Self::collection_has_nested_tokens(id) {296 if Self::collection_has_tokens(id) {299 return Err(<Error<T>>::CantBurnCollectionWithNestedTokens.into());297 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());300 }298 }301299302 // =========300 // =========972 );970 );973 }971 }974972975 fn collection_has_nested_tokens(collection_id: CollectionId) -> bool {973 fn collection_has_tokens(collection_id: CollectionId) -> bool {976 <TokenChildren<T>>::iter_prefix((collection_id,)).next().is_some()974 <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()977 }975 }978976979 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {977 fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {pallets/refungible/src/lib.rsdiffbeforeafterboth--- 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(<CommonError<T>>::CantDestroyNotEmptyCollection.into());
+ }
+
// =========
PalletCommon::destroy_collection(collection.0, sender)?;
@@ -225,6 +229,10 @@
Ok(())
}
+ fn collection_has_tokens(collection_id: CollectionId) -> bool {
+ <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
+ }
+
pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {
let burnt = <TokensBurnt<T>>::get(collection.id)
.checked_add(1)