difftreelog
chore add transfer event for `burn` and `create_multiple_items`
in: master
3 files changed
pallets/refungible/src/lib.rsdiffbeforeafterboth399399400 pub fn burn_token_unchecked(400 pub fn burn_token_unchecked(401 collection: &RefungibleHandle<T>,401 collection: &RefungibleHandle<T>,402 owner: &T::CrossAccountId,402 token_id: TokenId,403 token_id: TokenId,403 ) -> DispatchResult {404 ) -> DispatchResult {404 let burnt = <TokensBurnt<T>>::get(collection.id)405 let burnt = <TokensBurnt<T>>::get(collection.id)411 <TotalSupply<T>>::remove((collection.id, token_id));412 <TotalSupply<T>>::remove((collection.id, token_id));412 <Balance<T>>::remove_prefix((collection.id, token_id), None);413 <Balance<T>>::remove_prefix((collection.id, token_id), None);413 <Allowance<T>>::remove_prefix((collection.id, token_id), None);414 <Allowance<T>>::remove_prefix((collection.id, token_id), None);414 // TODO: ERC721 transfer event415416 <PalletEvm<T>>::deposit_log(417 ERC721Events::Transfer {418 from: *owner.as_eth(),419 to: H160::default(),420 token_id: token_id.into(),421 }422 .to_log(collection_id_to_address(collection.id)),423 );415 Ok(())424 Ok(())416 }425 }417426453 <Owned<T>>::remove((collection.id, owner, token));462 <Owned<T>>::remove((collection.id, owner, token));454 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);463 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);455 <AccountBalance<T>>::insert((collection.id, owner), account_balance);464 <AccountBalance<T>>::insert((collection.id, owner), account_balance);456 Self::burn_token_unchecked(collection, token)?;465 Self::burn_token_unchecked(collection, owner, token)?;457 <PalletEvm<T>>::deposit_log(466 <PalletEvm<T>>::deposit_log(458 ERC721Events::Transfer {467 ERC20Events::Transfer {459 from: *owner.as_eth(),468 from: *owner.as_eth(),460 to: H160::default(),469 to: H160::default(),461 token_id: token.into(),470 value: amount.into(),462 }471 }463 .to_log(collection_id_to_address(collection.id)),472 .to_log(collection_id_to_address(collection.id)),464 );473 );491 <Balance<T>>::remove((collection.id, token, owner));500 <Balance<T>>::remove((collection.id, token, owner));492 <AccountBalance<T>>::insert((collection.id, owner), account_balance);501 <AccountBalance<T>>::insert((collection.id, owner), account_balance);502503 if let Some(user) = Self::token_owner(collection.id, token) {504 <PalletEvm<T>>::deposit_log(505 ERC721Events::Transfer {506 from: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,507 to: *user.as_eth(),508 token_id: token.into(),509 }510 .to_log(collection_id_to_address(collection.id)),511 );512 }493 } else {513 } else {494 <Balance<T>>::insert((collection.id, token, owner), balance);514 <Balance<T>>::insert((collection.id, token, owner), balance);495 }515 }981 for (i, token) in data.into_iter().enumerate() {1001 for (i, token) in data.into_iter().enumerate() {982 let token_id = first_token_id + i as u32 + 1;1002 let token_id = first_token_id + i as u32 + 1;10031004 let receivers = token1005 .users1006 .into_iter()1007 .filter(|(_, amount)| *amount > 0)1008 .collect::<Vec<_>>();10091010 if let [(user, _)] = receivers.as_slice() {1011 // if there is exactly one receiver1012 <PalletEvm<T>>::deposit_log(1013 ERC721Events::Transfer {1014 from: H160::default(),1015 to: *user.as_eth(),1016 token_id: token_id.into(),1017 }1018 .to_log(collection_id_to_address(collection.id)),1019 );1020 } else if let [_, ..] = receivers.as_slice() {1021 // if there is more than one receiver1022 <PalletEvm<T>>::deposit_log(1023 ERC721Events::Transfer {1024 from: H160::default(),1025 to: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,1026 token_id: token_id.into(),1027 }1028 .to_log(collection_id_to_address(collection.id)),1029 );1030 }9831031984 for (user, amount) in token.users.into_iter() {1032 for (user, amount) in receivers.into_iter() {985 if amount == 0 {986 continue;987 }988989 <PalletEvm<T>>::deposit_log(1033 <PalletEvm<T>>::deposit_log(990 ERC20Events::Transfer {1034 ERC20Events::Transfer {997 TokenId(token_id),1041 TokenId(token_id),998 )),1042 )),999 );1043 );1000 <PalletEvm<T>>::deposit_log(1001 ERC721Events::Transfer {1002 from: H160::default(),1003 to: *user.as_eth(),1004 token_id: token_id.into(),1005 }1006 .to_log(collection_id_to_address(collection.id)),1007 );1008 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(1044 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(1009 collection.id,1045 collection.id,1010 TokenId(token_id),1046 TokenId(token_id),tests/src/eth/reFungible.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {createCollectionExpectSuccess, transfer, UNIQUE} from '../util/helpers';17import {createCollectionExpectSuccess, transfer, UNIQUE} from '../util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, tokenIdToAddress} from './util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress} from './util/helpers';19import reFungibleAbi from './reFungibleAbi.json';19import reFungibleAbi from './reFungibleAbi.json';20import reFungibleTokenAbi from './reFungibleTokenAbi.json';20import reFungibleTokenAbi from './reFungibleTokenAbi.json';21import {expect} from 'chai';21import {expect} from 'chai';225 const result = await contract.methods.burn(tokenId).send();225 const result = await contract.methods.burn(tokenId).send();226 const events = normalizeEvents(result.events);226 const events = normalizeEvents(result.events);227228 expect(events).to.be.deep.equal([227 expect(events).to.include.deep.members([229 {228 {230 address: collectionIdAddress,229 address: collectionIdAddress,231 event: 'Transfer',230 event: 'Transfer',333 await tokenContract.methods.repartition(2).send();332 await tokenContract.methods.repartition(2).send();334 await tokenContract.methods.transfer(receiver, 1).send();333 await tokenContract.methods.transfer(receiver, 1).send();335334336 let transfer;335 const events = await recordEvents(contract, async () => 337 contract.events.Transfer({}, function(_error: any, event: any){ transfer = event;});338 await tokenContract.methods.transfer(receiver, 1).send();336 await tokenContract.methods.transfer(receiver, 1).send());339 const events = normalizeEvents([transfer]);340 expect(events).to.deep.equal([337 expect(events).to.deep.equal([341 {338 {342 address: collectionIdAddress,339 address: collectionIdAddress,366363367 await tokenContract.methods.repartition(2).send();364 await tokenContract.methods.repartition(2).send();368 365 369 let transfer;366 const events = await recordEvents(contract, async () => 370 contract.events.Transfer({}, function(_error: any, event: any){ transfer = event;});371 await tokenContract.methods.transfer(receiver, 1).send();367 await tokenContract.methods.transfer(receiver, 1).send());372368 373 const events = normalizeEvents([transfer]);374 expect(events).to.deep.equal([369 expect(events).to.deep.equal([375 {370 {376 address: collectionIdAddress,371 address: collectionIdAddress,tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth277 {277 {278 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});278 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});279 const events = normalizeEvents(result.events);279 const events = normalizeEvents(result.events);280 expect(events).to.be.deep.equal([280 expect(events).to.include.deep.members([281 {281 {282 address,282 address,283 event: 'Transfer',283 event: 'Transfer',329 {329 {330 const result = await contract.methods.transfer(receiver, 50).send({from: owner});330 const result = await contract.methods.transfer(receiver, 50).send({from: owner});331 const events = normalizeEvents(result.events);331 const events = normalizeEvents(result.events);332 expect(events).to.be.deep.equal([332 expect(events).to.include.deep.members([333 {333 {334 address,334 address,335 event: 'Transfer',335 event: 'Transfer',443 ]);443 ]);444 });444 });445446 itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {447 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);448 const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);449 const helper = evmCollectionHelpers(web3, caller);450 const result = await helper.methods.createRefungibleCollection('Mint collection', '6', '6').send();451 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);452 const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});453454 const tokenId = await contract.methods.nextTokenId().call();455 await contract.methods.mint(caller, tokenId).send();456457 const address = tokenIdToAddress(collectionId, tokenId);458459 const tokenContract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: caller, ...GAS_ARGS});460 await tokenContract.methods.repartition(2).send();461 await tokenContract.methods.transfer(receiver, 1).send();462463 const events = await recordEvents(contract, async () => 464 await tokenContract.methods.burnFrom(caller, 1).send());465 expect(events).to.deep.equal([466 {467 address: collectionIdAddress,468 event: 'Transfer',469 args: {470 from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',471 to: receiver,472 tokenId,473 },474 },475 ]);476 });445});477});446478447describe('Refungible: Fees', () => {479describe('Refungible: Fees', () => {