git.delta.rocks / unique-network / refs/commits / 101a18907270

difftreelog

fix unnest tokens on transfer

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

3 files changed

modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -256,6 +256,11 @@
 			// from != to
 			if balance_from == 0 {
 				<Balance<T>>::remove((collection.id, from));
+				<PalletStructure<T>>::unnest_if_nested(
+					from,
+					collection.id,
+					TokenId::default()
+				);
 			} else {
 				<Balance<T>>::insert((collection.id, from), balance_from);
 			}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
340 .checked_sub(1)340 .checked_sub(1)
341 .ok_or(ArithmeticError::Overflow)?;341 .ok_or(ArithmeticError::Overflow)?;
342
343 // =========
342344
343 if balance == 0 {345 if balance == 0 {
344 <AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));346 <AccountBalance<T>>::remove((collection.id, token_data.owner.clone()));
345 } else {347 } else {
346 <AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);348 <AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);
347 }349 }
348350
351 <PalletStructure<T>>::unnest_if_nested(
349 if let Some(owner) = T::CrossTokenAddressMapping::address_to_token(&token_data.owner) {352 &token_data.owner,
350 Self::unnest(owner, (collection.id, token));353 collection.id,
351 }354 token
352355 );
353 // =========
354356
355 <Owned<T>>::remove((collection.id, &token_data.owner, token));357 <Owned<T>>::remove((collection.id, &token_data.owner, token));
356 <TokensBurnt<T>>::insert(collection.id, burnt);358 <TokensBurnt<T>>::insert(collection.id, burnt);
593595
594 // =========596 // =========
597
598 <PalletStructure<T>>::unnest_if_nested(
599 from,
600 collection.id,
601 token
602 );
595603
596 <TokenData<T>>::insert(604 <TokenData<T>>::insert(
597 (collection.id, token),605 (collection.id, token),
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -395,6 +395,11 @@
 			// from != to
 			if balance_from == 0 {
 				<Balance<T>>::remove((collection.id, token, from));
+				<PalletStructure<T>>::unnest_if_nested(
+					from,
+					collection.id,
+					token
+				);
 			} else {
 				<Balance<T>>::insert((collection.id, token, from), balance_from);
 			}