git.delta.rocks / unique-network / refs/commits / 004643cad6df

difftreelog

fix unnest NFT from parent

Daniel Shiposha2022-06-03parent: #4d135e3.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -604,7 +604,7 @@
 
 		// =========
 
-		<PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
+		<PalletStructure<T>>::unnest_if_nested(&token_data.owner, collection.id, token);
 
 		<TokenData<T>>::insert(
 			(collection.id, token),
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -191,8 +191,8 @@
 		token_id: TokenId,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {
-			d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)
+		Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
+			collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)
 		})
 	}
 
@@ -203,10 +203,10 @@
 		token_id: TokenId,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {
-			d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;
+		Self::try_exec_if_owner_is_valid_nft(under, |collection, parent_id| {
+			collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;
 
-			d.nest(parent_id, (collection_id, token_id));
+			collection.nest(parent_id, (collection_id, token_id));
 
 			Ok(())
 		})
@@ -217,8 +217,8 @@
 		collection_id: CollectionId,
 		token_id: TokenId,
 	) {
-		Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {
-			d.nest(parent_id, (collection_id, token_id))
+		Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
+			collection.nest(parent_id, (collection_id, token_id))
 		});
 	}
 
@@ -227,8 +227,8 @@
 		collection_id: CollectionId,
 		token_id: TokenId,
 	) {
-		Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {
-			d.unnest(parent_id, (collection_id, token_id))
+		Self::exec_if_owner_is_valid_nft(owner, |collection, parent_id| {
+			collection.unnest(parent_id, (collection_id, token_id))
 		});
 	}
 
@@ -236,8 +236,8 @@
 		account: &T::CrossAccountId,
 		action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),
 	) {
-		Self::try_exec_if_owner_is_valid_nft(account, |d, id| {
-			action(d, id);
+		Self::try_exec_if_owner_is_valid_nft(account, |collection, id| {
+			action(collection, id);
 			Ok(())
 		})
 		.unwrap();
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
120 ], 'Children contents check at nesting #2');120 ], 'Children contents check at nesting #2');
121121
122 // Move token B to a different user outside the nesting tree122 // Move token B to a different user outside the nesting tree
123 await transferFromExpectSuccess(collectionA, tokenB, alice, targetAddress, bob);123 await transferExpectSuccess(collectionA, tokenB, alice, bob);
124 children = await getTokenChildren(api, collectionA, targetToken);124 children = await getTokenChildren(api, collectionA, targetToken);
125 expect(children.length).to.be.equal(1, 'Children length check at unnesting');125 expect(children.length).to.be.equal(1, 'Children length check at unnesting');
126 expect(children).to.be.have.deep.members([126 expect(children).to.be.have.deep.members([
290 });290 });
291 });291 });
292
293 // TODO delete if this is actually wrong
294 // TODO remake all other nesting tests if this is right
295 it('Affirms that transfer is disallowed to transfer nested tokens', async () => {
296 await usingApi(async () => {
297 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
298 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
299
300 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');
301 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});
302
303 await transferExpectFailure(collection, tokenB, alice, bob);
304 });
305 });
306292
307 it('Disallows excessive token nesting', async () => {293 it('Disallows excessive token nesting', async () => {
308 await usingApi(async api => {294 await usingApi(async api => {