difftreelog
fix destroy only not empty collections
in: master
4 files changed
pallets/common/src/lib.rsdiffbeforeafterboth331 MustBeTokenOwner,331 MustBeTokenOwner,332 /// No permission to perform action332 /// No permission to perform action333 NoPermission,333 NoPermission,334 /// Destroying only empty collections is allowed335 CantDestroyNotEmptyCollection,334 /// Collection is not in mint mode.336 /// Collection is not in mint mode.335 PublicMintingNotAllowed,337 PublicMintingNotAllowed,336 /// Address is not in allow list.338 /// Address is not in allow list.pallets/fungible/src/lib.rsdiffbeforeafterboth145 ) -> DispatchResult {145 ) -> DispatchResult {146 let id = collection.id;146 let id = collection.id;147148 if Self::collection_has_tokens(id) {149 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());150 }147151148 // =========152 // =========149153155 Ok(())159 Ok(())156 }160 }161162 fn collection_has_tokens(collection_id: CollectionId) -> bool {163 <TotalSupply<T>>::get(collection_id) != 0164 }157165158 pub fn burn(166 pub fn burn(159 collection: &FungibleHandle<T>,167 collection: &FungibleHandle<T>,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.rsdiffbeforeafterboth210 ) -> DispatchResult {210 ) -> DispatchResult {211 let id = collection.id;211 let id = collection.id;212213 if Self::collection_has_tokens(id) {214 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());215 }212216213 // =========217 // =========214218225 Ok(())229 Ok(())226 }230 }231232 fn collection_has_tokens(collection_id: CollectionId) -> bool {233 <TokenData<T>>::iter_prefix((collection_id,)).next().is_some()234 }227235228 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)