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.jsondiffbeforeafterboth1[2 {3 "anonymous": false,4 "inputs": [5 {6 "indexed": true,7 "internalType": "address",8 "name": "collectionId",9 "type": "address"10 }11 ],12 "name": "CollectionChanged",13 "type": "event"14 },15 {16 "anonymous": false,17 "inputs": [18 {19 "indexed": true,20 "internalType": "address",21 "name": "owner",22 "type": "address"23 },24 {25 "indexed": true,26 "internalType": "address",27 "name": "collectionId",28 "type": "address"29 }30 ],31 "name": "CollectionCreated",32 "type": "event"33 },34 {35 "anonymous": false,36 "inputs": [37 {38 "indexed": true,39 "internalType": "address",40 "name": "collectionId",41 "type": "address"42 }43 ],44 "name": "CollectionDestroyed",45 "type": "event"46 },47 {48 "inputs": [49 { "internalType": "uint32", "name": "collectionId", "type": "uint32" }50 ],51 "name": "collectionAddress",52 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],53 "stateMutability": "view",54 "type": "function"55 },56 {57 "inputs": [],58 "name": "collectionCreationFee",59 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],60 "stateMutability": "view",61 "type": "function"62 },63 {64 "inputs": [65 {66 "internalType": "address",67 "name": "collectionAddress",68 "type": "address"69 }70 ],71 "name": "collectionId",72 "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],73 "stateMutability": "view",74 "type": "function"75 },76 {77 "inputs": [78 { "internalType": "string", "name": "name", "type": "string" },79 { "internalType": "uint8", "name": "decimals", "type": "uint8" },80 { "internalType": "string", "name": "description", "type": "string" },81 { "internalType": "string", "name": "tokenPrefix", "type": "string" }82 ],83 "name": "createFTCollection",84 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],85 "stateMutability": "payable",86 "type": "function"87 },88 {89 "inputs": [90 { "internalType": "string", "name": "name", "type": "string" },91 { "internalType": "string", "name": "description", "type": "string" },92 { "internalType": "string", "name": "tokenPrefix", "type": "string" }93 ],94 "name": "createNFTCollection",95 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],96 "stateMutability": "payable",97 "type": "function"98 },99 {100 "inputs": [101 { "internalType": "string", "name": "name", "type": "string" },102 { "internalType": "string", "name": "description", "type": "string" },103 { "internalType": "string", "name": "tokenPrefix", "type": "string" }104 ],105 "name": "createRFTCollection",106 "outputs": [{ "internalType": "address", "name": "", "type": "address" }],107 "stateMutability": "payable",108 "type": "function"109 },110 {111 "inputs": [112 {113 "internalType": "address",114 "name": "collectionAddress",115 "type": "address"116 }117 ],118 "name": "destroyCollection",119 "outputs": [],120 "stateMutability": "nonpayable",121 "type": "function"122 },123 {124 "inputs": [125 {126 "internalType": "address",127 "name": "collectionAddress",128 "type": "address"129 }130 ],131 "name": "isCollectionExist",132 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],133 "stateMutability": "view",134 "type": "function"135 },136 {137 "inputs": [138 { "internalType": "address", "name": "collection", "type": "address" },139 { "internalType": "string", "name": "baseUri", "type": "string" }140 ],141 "name": "makeCollectionERC721MetadataCompatible",142 "outputs": [],143 "stateMutability": "nonpayable",144 "type": "function"145 },146 {147 "inputs": [148 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }149 ],150 "name": "supportsInterface",151 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],152 "stateMutability": "view",153 "type": "function"154 }155]tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -17,6 +17,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/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