git.delta.rocks / unique-network / refs/commits / 79ec93ec606f

difftreelog

fix destroy only not empty collections

Daniel Shiposha2022-05-27parent: #b5533c6.patch.diff
in: master

4 files changed

modifiedpallets/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.
modifiedpallets/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,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- 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(<Error<T>>::CantBurnCollectionWithNestedTokens.into());
+		if Self::collection_has_tokens(id) {
+			return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());
 		}
 
 		// =========
@@ -972,8 +970,8 @@
 		);
 	}
 
-	fn collection_has_nested_tokens(collection_id: CollectionId) -> bool {
-		<TokenChildren<T>>::iter_prefix((collection_id,)).next().is_some()
+	fn collection_has_tokens(collection_id: CollectionId) -> bool {
+		<TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
 	}
 
 	fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
210 ) -> DispatchResult {210 ) -> DispatchResult {
211 let id = collection.id;211 let id = collection.id;
212
213 if Self::collection_has_tokens(id) {
214 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());
215 }
212216
213 // =========217 // =========
214218
225 Ok(())229 Ok(())
226 }230 }
231
232 fn collection_has_tokens(collection_id: CollectionId) -> bool {
233 <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
234 }
227235
228 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {236 pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {
229 let burnt = <TokensBurnt<T>>::get(collection.id)237 let burnt = <TokensBurnt<T>>::get(collection.id)