git.delta.rocks / unique-network / refs/commits / ea3ed4f319a6

difftreelog

fix deny zero NFT transfer/burn if not owned/allowed

Daniel Shiposha2022-12-07parent: #21b4b8a.patch.diff
in: master

2 files changed

modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
291 <CommonWeights<T>>::burn_item(),291 <CommonWeights<T>>::burn_item(),
292 )292 )
293 } else {293 } else {
294 <Pallet<T>>::check_token_immediate_ownership(self, token, &sender)?;
294 Ok(().into())295 Ok(().into())
295 }296 }
296 }297 }
320 <CommonWeights<T>>::transfer(),321 <CommonWeights<T>>::transfer(),
321 )322 )
322 } else {323 } else {
324 <Pallet<T>>::check_token_immediate_ownership(self, token, &from)?;
323 Ok(().into())325 Ok(().into())
324 }326 }
325 }327 }
360 <CommonWeights<T>>::transfer_from(),362 <CommonWeights<T>>::transfer_from(),
361 )363 )
362 } else {364 } else {
365 <Pallet<T>>::check_allowed(self, &sender, &from, token, nesting_budget)?;
366
363 Ok(().into())367 Ok(().into())
364 }368 }
380 <CommonWeights<T>>::burn_from(),384 <CommonWeights<T>>::burn_from(),
381 )385 )
382 } else {386 } else {
387 <Pallet<T>>::check_allowed(self, &sender, &from, token, nesting_budget)?;
388
383 Ok(().into())389 Ok(().into())
384 }390 }
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -814,6 +814,20 @@
 		<PalletCommon<T>>::set_property_permission(collection, sender, permission)
 	}
 
+	pub fn check_token_immediate_ownership(
+		collection: &NonfungibleHandle<T>,
+		token: TokenId,
+		possible_owner: &T::CrossAccountId,
+	) -> DispatchResult {
+		let token_data =
+			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
+		ensure!(
+			&token_data.owner == possible_owner,
+			<CommonError<T>>::NoPermission
+		);
+		Ok(())
+	}
+
 	/// Transfer NFT token from one account to another.
 	///
 	/// `from` account stops being the owner and `to` account becomes the owner of the token.