git.delta.rocks / unique-network / refs/commits / 62d6042adc19

difftreelog

feat add event TokenChanged

Trubnikov Sergey2022-12-08parent: #7680e66.patch.diff
in: master

8 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
65 collection_id: address,65 collection_id: address,
66 },66 },
67
68 /// The token has been changed.
69 TokenChanged {
70 /// Collection ID.
71 #[indexed]
72 collection_id: address,
73 /// Token ID.
74 token_id: uint256,
75 },
67}76}
6877
69/// Does not always represent a full collection, for RFT it is either78/// Does not always represent a full collection, for RFT it is either
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
109use pallet_common::{109use pallet_common::{
110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,110 Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
111 eth::collection_id_to_address,111 eth::collection_id_to_address, erc::CollectionHelpersEvents,
112};112};
113use pallet_structure::{Pallet as PalletStructure, Error as StructureError};113use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
114use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};114use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
115use sp_core::H160;115use sp_core::{H160, Get};
116use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};116use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
117use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};117use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
118use core::ops::Deref;118use core::ops::Deref;
674 }674 }
675 }675 }
676
677 <PalletEvm<T>>::deposit_log(
678 CollectionHelpersEvents::TokenChanged {
679 collection_id: collection_id_to_address(collection.id),
680 token_id: token_id.into(),
681 }
682 .to_log(T::ContractAddress::get()),
683 );
676 }684 }
677685
678 Ok(())686 Ok(())
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
102use pallet_evm_coder_substrate::WithRecorder;102use pallet_evm_coder_substrate::WithRecorder;
103use pallet_common::{103use pallet_common::{
104 CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,104 CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,
105 Event as CommonEvent, Pallet as PalletCommon,105 Event as CommonEvent, Pallet as PalletCommon, erc::CollectionHelpersEvents,
106};106};
107use pallet_structure::Pallet as PalletStructure;107use pallet_structure::Pallet as PalletStructure;
108use scale_info::TypeInfo;108use scale_info::TypeInfo;
109use sp_core::H160;109use sp_core::{Get, H160};
110use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};110use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
111use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};111use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
112use up_data_structs::{112use up_data_structs::{
650 }650 }
651 }651 }
652
653 <PalletEvm<T>>::deposit_log(
654 CollectionHelpersEvents::TokenChanged {
655 collection_id: collection_id_to_address(collection.id),
656 token_id: token_id.into(),
657 }
658 .to_log(T::ContractAddress::get()),
659 );
652 }660 }
653661
654 Ok(())662 Ok(())
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth
22 event CollectionCreated(address indexed owner, address indexed collectionId);22 event CollectionCreated(address indexed owner, address indexed collectionId);
23 event CollectionDestroyed(address indexed collectionId);23 event CollectionDestroyed(address indexed collectionId);
24 event CollectionChanged(address indexed collectionId);24 event CollectionChanged(address indexed collectionId);
25 event TokenChanged(address indexed collectionId, uint256 tokenId);
25}26}
2627
27/// @title Contract, which allows users to operate with collections28/// @title Contract, which allows users to operate with collections
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
44 "name": "CollectionDestroyed",44 "name": "CollectionDestroyed",
45 "type": "event"45 "type": "event"
46 },46 },
47 {
48 "anonymous": false,
49 "inputs": [
50 {
51 "indexed": true,
52 "internalType": "address",
53 "name": "collectionId",
54 "type": "address"
55 },
56 {
57 "indexed": false,
58 "internalType": "uint256",
59 "name": "tokenId",
60 "type": "uint256"
61 }
62 ],
63 "name": "TokenChanged",
64 "type": "event"
65 },
47 {66 {
48 "inputs": [67 "inputs": [
49 { "internalType": "uint32", "name": "collectionId", "type": "uint32" }68 { "internalType": "uint32", "name": "collectionId", "type": "uint32" }
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
17 event CollectionCreated(address indexed owner, address indexed collectionId);17 event CollectionCreated(address indexed owner, address indexed collectionId);
18 event CollectionDestroyed(address indexed collectionId);18 event CollectionDestroyed(address indexed collectionId);
19 event CollectionChanged(address indexed collectionId);19 event CollectionChanged(address indexed collectionId);
20 event TokenChanged(address indexed collectionId, uint256 tokenId);
20}21}
2122
22/// @title Contract, which allows users to operate with collections23/// @title Contract, which allows users to operate with collections
modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
355 unsubscribe();355 unsubscribe();
356 });356 });
357 357
358 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
359 const owner = await helper.eth.createAccountWithBalance(donor);
360 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
361 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
362 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
363 const result = await collection.methods.mint(owner).send({from: owner});
364 const tokenId = result.events.Transfer.returnValues.tokenId;
365 await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner});
366
367
368 const ethEvents: any = [];
369 collectionHelper.events.allEvents((_: any, event: any) => {
370 ethEvents.push(event);
371 });
372 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);
373 {
374 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
375 expect(ethEvents).to.be.like([
376 {
377 event: 'TokenChanged',
378 returnValues: {
379 collectionId: collectionAddress
380 }
381 }
382 ]);
383 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
384 ethEvents.pop();
385 subEvents.pop();
386 }
387 {
388 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
389 expect(ethEvents).to.be.like([
390 {
391 event: 'TokenChanged',
392 returnValues: {
393 collectionId: collectionAddress
394 }
395 }
396 ]);
397 expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);
398 }
399 unsubscribe();
400 });
358});401});