difftreelog
feat add event TokenChanged
in: master
8 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -64,6 +64,15 @@
#[indexed]
collection_id: address,
},
+
+ /// The token has been changed.
+ TokenChanged {
+ /// Collection ID.
+ #[indexed]
+ collection_id: address,
+ /// Token ID.
+ token_id: uint256,
+ },
}
/// Does not always represent a full collection, for RFT it is either
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -108,11 +108,11 @@
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
- eth::collection_id_to_address,
+ eth::collection_id_to_address, erc::CollectionHelpersEvents,
};
use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_core::H160;
+use sp_core::{H160, Get};
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
use core::ops::Deref;
@@ -673,6 +673,14 @@
));
}
}
+
+ <PalletEvm<T>>::deposit_log(
+ CollectionHelpersEvents::TokenChanged {
+ collection_id: collection_id_to_address(collection.id),
+ token_id: token_id.into(),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
}
Ok(())
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -102,11 +102,11 @@
use pallet_evm_coder_substrate::WithRecorder;
use pallet_common::{
CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,
- Event as CommonEvent, Pallet as PalletCommon,
+ Event as CommonEvent, Pallet as PalletCommon, erc::CollectionHelpersEvents,
};
use pallet_structure::Pallet as PalletStructure;
use scale_info::TypeInfo;
-use sp_core::H160;
+use sp_core::{Get, H160};
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
use up_data_structs::{
@@ -649,6 +649,14 @@
));
}
}
+
+ <PalletEvm<T>>::deposit_log(
+ CollectionHelpersEvents::TokenChanged {
+ collection_id: collection_id_to_address(collection.id),
+ token_id: token_id.into(),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
}
Ok(())
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -22,6 +22,7 @@
event CollectionCreated(address indexed owner, address indexed collectionId);
event CollectionDestroyed(address indexed collectionId);
event CollectionChanged(address indexed collectionId);
+ event TokenChanged(address indexed collectionId, uint256 tokenId);
}
/// @title Contract, which allows users to operate with collections
tests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -45,6 +45,25 @@
"type": "event"
},
{
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "internalType": "address",
+ "name": "collectionId",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "TokenChanged",
+ "type": "event"
+ },
+ {
"inputs": [
{ "internalType": "uint32", "name": "collectionId", "type": "uint32" }
],
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415/// @dev inlined interface16interface CollectionHelpersEvents {17 event CollectionCreated(address indexed owner, address indexed collectionId);18 event CollectionDestroyed(address indexed collectionId);19 event CollectionChanged(address indexed collectionId);20}2122/// @title Contract, which allows users to operate with collections23/// @dev the ERC-165 identifier for this interface is 0xe65011aa24interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {25 /// Create an NFT collection26 /// @param name Name of the collection27 /// @param description Informative description of the collection28 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications29 /// @return address Address of the newly created collection30 /// @dev EVM selector for this function is: 0x844af658,31 /// or in textual repr: createNFTCollection(string,string,string)32 function createNFTCollection(33 string memory name,34 string memory description,35 string memory tokenPrefix36 ) external payable returns (address);3738 // /// Create an NFT collection39 // /// @param name Name of the collection40 // /// @param description Informative description of the collection41 // /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications42 // /// @return address Address of the newly created collection43 // /// @dev EVM selector for this function is: 0xe34a6844,44 // /// or in textual repr: createNonfungibleCollection(string,string,string)45 // function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) external payable returns (address);4647 /// @dev EVM selector for this function is: 0xab173450,48 /// or in textual repr: createRFTCollection(string,string,string)49 function createRFTCollection(50 string memory name,51 string memory description,52 string memory tokenPrefix53 ) external payable returns (address);5455 /// @dev EVM selector for this function is: 0x7335b79f,56 /// or in textual repr: createFTCollection(string,uint8,string,string)57 function createFTCollection(58 string memory name,59 uint8 decimals,60 string memory description,61 string memory tokenPrefix62 ) external payable returns (address);6364 /// @dev EVM selector for this function is: 0x85624258,65 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)66 function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;6768 /// @dev EVM selector for this function is: 0x564e321f,69 /// or in textual repr: destroyCollection(address)70 function destroyCollection(address collectionAddress) external;7172 /// Check if a collection exists73 /// @param collectionAddress Address of the collection in question74 /// @return bool Does the collection exist?75 /// @dev EVM selector for this function is: 0xc3de1494,76 /// or in textual repr: isCollectionExist(address)77 function isCollectionExist(address collectionAddress) external view returns (bool);7879 /// @dev EVM selector for this function is: 0xd23a7ab1,80 /// or in textual repr: collectionCreationFee()81 function collectionCreationFee() external view returns (uint256);8283 /// Returns address of a collection.84 /// @param collectionId - CollectionId of the collection85 /// @return eth mirror address of the collection86 /// @dev EVM selector for this function is: 0x2e716683,87 /// or in textual repr: collectionAddress(uint32)88 function collectionAddress(uint32 collectionId) external view returns (address);8990 /// Returns collectionId of a collection.91 /// @param collectionAddress - Eth address of the collection92 /// @return collectionId of the collection93 /// @dev EVM selector for this function is: 0xb5cb7498,94 /// or in textual repr: collectionId(address)95 function collectionId(address collectionAddress) external view returns (uint32);96}1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12 function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415/// @dev inlined interface16interface CollectionHelpersEvents {17 event CollectionCreated(address indexed owner, address indexed collectionId);18 event CollectionDestroyed(address indexed collectionId);19 event CollectionChanged(address indexed collectionId);20 event TokenChanged(address indexed collectionId, uint256 tokenId);21}2223/// @title Contract, which allows users to operate with collections24/// @dev the ERC-165 identifier for this interface is 0xe65011aa25interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {26 /// Create an NFT collection27 /// @param name Name of the collection28 /// @param description Informative description of the collection29 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications30 /// @return address Address of the newly created collection31 /// @dev EVM selector for this function is: 0x844af658,32 /// or in textual repr: createNFTCollection(string,string,string)33 function createNFTCollection(34 string memory name,35 string memory description,36 string memory tokenPrefix37 ) external payable returns (address);3839 // /// Create an NFT collection40 // /// @param name Name of the collection41 // /// @param description Informative description of the collection42 // /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications43 // /// @return address Address of the newly created collection44 // /// @dev EVM selector for this function is: 0xe34a6844,45 // /// or in textual repr: createNonfungibleCollection(string,string,string)46 // function createNonfungibleCollection(string memory name, string memory description, string memory tokenPrefix) external payable returns (address);4748 /// @dev EVM selector for this function is: 0xab173450,49 /// or in textual repr: createRFTCollection(string,string,string)50 function createRFTCollection(51 string memory name,52 string memory description,53 string memory tokenPrefix54 ) external payable returns (address);5556 /// @dev EVM selector for this function is: 0x7335b79f,57 /// or in textual repr: createFTCollection(string,uint8,string,string)58 function createFTCollection(59 string memory name,60 uint8 decimals,61 string memory description,62 string memory tokenPrefix63 ) external payable returns (address);6465 /// @dev EVM selector for this function is: 0x85624258,66 /// or in textual repr: makeCollectionERC721MetadataCompatible(address,string)67 function makeCollectionERC721MetadataCompatible(address collection, string memory baseUri) external;6869 /// @dev EVM selector for this function is: 0x564e321f,70 /// or in textual repr: destroyCollection(address)71 function destroyCollection(address collectionAddress) external;7273 /// Check if a collection exists74 /// @param collectionAddress Address of the collection in question75 /// @return bool Does the collection exist?76 /// @dev EVM selector for this function is: 0xc3de1494,77 /// or in textual repr: isCollectionExist(address)78 function isCollectionExist(address collectionAddress) external view returns (bool);7980 /// @dev EVM selector for this function is: 0xd23a7ab1,81 /// or in textual repr: collectionCreationFee()82 function collectionCreationFee() external view returns (uint256);8384 /// Returns address of a collection.85 /// @param collectionId - CollectionId of the collection86 /// @return eth mirror address of the collection87 /// @dev EVM selector for this function is: 0x2e716683,88 /// or in textual repr: collectionAddress(uint32)89 function collectionAddress(uint32 collectionId) external view returns (address);9091 /// Returns collectionId of a collection.92 /// @param collectionAddress - Eth address of the collection93 /// @return collectionId of the collection94 /// @dev EVM selector for this function is: 0xb5cb7498,95 /// or in textual repr: collectionId(address)96 function collectionId(address collectionAddress) external view returns (uint32);97}tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -354,5 +354,48 @@
}
unsubscribe();
});
-
+
+ itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const result = await collection.methods.mint(owner).send({from: owner});
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner});
+
+
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);
+ {
+ await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'TokenChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'TokenChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);
+ }
+ unsubscribe();
+ });
});
\ No newline at end of file