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
--- 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
modifiedpallets/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(())
modifiedpallets/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(())
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/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
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
before · tests/src/eth/abi/collectionHelpers.json
1[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]
after · tests/src/eth/abi/collectionHelpers.json
1[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    "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  },66  {67    "inputs": [68      { "internalType": "uint32", "name": "collectionId", "type": "uint32" }69    ],70    "name": "collectionAddress",71    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],72    "stateMutability": "view",73    "type": "function"74  },75  {76    "inputs": [],77    "name": "collectionCreationFee",78    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],79    "stateMutability": "view",80    "type": "function"81  },82  {83    "inputs": [84      {85        "internalType": "address",86        "name": "collectionAddress",87        "type": "address"88      }89    ],90    "name": "collectionId",91    "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }],92    "stateMutability": "view",93    "type": "function"94  },95  {96    "inputs": [97      { "internalType": "string", "name": "name", "type": "string" },98      { "internalType": "uint8", "name": "decimals", "type": "uint8" },99      { "internalType": "string", "name": "description", "type": "string" },100      { "internalType": "string", "name": "tokenPrefix", "type": "string" }101    ],102    "name": "createFTCollection",103    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],104    "stateMutability": "payable",105    "type": "function"106  },107  {108    "inputs": [109      { "internalType": "string", "name": "name", "type": "string" },110      { "internalType": "string", "name": "description", "type": "string" },111      { "internalType": "string", "name": "tokenPrefix", "type": "string" }112    ],113    "name": "createNFTCollection",114    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],115    "stateMutability": "payable",116    "type": "function"117  },118  {119    "inputs": [120      { "internalType": "string", "name": "name", "type": "string" },121      { "internalType": "string", "name": "description", "type": "string" },122      { "internalType": "string", "name": "tokenPrefix", "type": "string" }123    ],124    "name": "createRFTCollection",125    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],126    "stateMutability": "payable",127    "type": "function"128  },129  {130    "inputs": [131      {132        "internalType": "address",133        "name": "collectionAddress",134        "type": "address"135      }136    ],137    "name": "destroyCollection",138    "outputs": [],139    "stateMutability": "nonpayable",140    "type": "function"141  },142  {143    "inputs": [144      {145        "internalType": "address",146        "name": "collectionAddress",147        "type": "address"148      }149    ],150    "name": "isCollectionExist",151    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],152    "stateMutability": "view",153    "type": "function"154  },155  {156    "inputs": [157      { "internalType": "address", "name": "collection", "type": "address" },158      { "internalType": "string", "name": "baseUri", "type": "string" }159    ],160    "name": "makeCollectionERC721MetadataCompatible",161    "outputs": [],162    "stateMutability": "nonpayable",163    "type": "function"164  },165  {166    "inputs": [167      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }168    ],169    "name": "supportsInterface",170    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],171    "stateMutability": "view",172    "type": "function"173  }174]
modifiedtests/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
modifiedtests/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