git.delta.rocks / unique-network / refs/commits / 59683d4fb2c6

difftreelog

feat add evm event `CollectionChanged` for sub events : `CollectionPropertySet`, `CollectionPropertyDeleted`, `PropertyPermissionSet`

Trubnikov Sergey2022-12-06parent: #6c3810b.patch.diff
in: master

7 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -58,6 +58,12 @@
 		#[indexed]
 		collection_id: address,
 	},
+	/// The collection has been changed.
+	CollectionChanged {
+		/// Collection ID.
+		#[indexed]
+		collection_id: address,
+	},
 }
 
 /// Does not always represent a full collection, for RFT it is either
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1036,6 +1036,12 @@
 		.map_err(<Error<T>>::from)?;
 
 		Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.to_log(T::ContractAddress::get()),
+		);
 
 		Ok(())
 	}
@@ -1115,6 +1121,12 @@
 			collection.id,
 			property_key,
 		));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.to_log(T::ContractAddress::get()),
+		);
 
 		Ok(())
 	}
@@ -1209,6 +1221,12 @@
 			collection.id,
 			property_permission.key,
 		));
+		<PalletEvm<T>>::deposit_log(
+			erc::CollectionHelpersEvents::CollectionChanged {
+				collection_id: eth::collection_id_to_address(collection.id),
+			}
+			.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
@@ -21,6 +21,7 @@
 contract CollectionHelpersEvents {
 	event CollectionCreated(address indexed owner, address indexed collectionId);
 	event CollectionDestroyed(address indexed collectionId);
+	event CollectionChanged(address indexed collectionId);
 }
 
 /// @title Contract, which allows users to operate with collections
modifiedtests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -5,6 +5,19 @@
       {
         "indexed": true,
         "internalType": "address",
+        "name": "collectionId",
+        "type": "address"
+      }
+    ],
+    "name": "CollectionChanged",
+    "type": "event"
+  },
+  {
+    "anonymous": false,
+    "inputs": [
+      {
+        "indexed": true,
+        "internalType": "address",
         "name": "owner",
         "type": "address"
       },
modifiedtests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth
--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -16,6 +16,7 @@
 interface CollectionHelpersEvents {
 	event CollectionCreated(address indexed owner, address indexed collectionId);
 	event CollectionDestroyed(address indexed collectionId);
+	event CollectionChanged(address indexed collectionId);
 }
 
 /// @title Contract, which allows users to operate with collections
addedtests/src/eth/events.test.tsdiffbeforeafterboth
after · tests/src/eth/events.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import { expect } from 'chai';19import { itEth, usingEthPlaygrounds } from './util';2021describe.only('NFT events', () => {22    let donor: IKeyringPair;23  24    before(async function () {25      await usingEthPlaygrounds(async (_helper, privateKey) => {26        donor = await privateKey({filename: __filename});27      });28    });2930    itEth('Create event', async ({helper}) => {31        const owner = await helper.eth.createAccountWithBalance(donor);32        const {collectionAddress, events} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');33        expect(events).to.be.like([34            {35                event: 'CollectionCreated',36                args: {37                    owner: owner,38                    collectionId: collectionAddress39                }40            }41        ]);42    });4344    itEth('Destroy event', async ({helper}) => {45        const owner = await helper.eth.createAccountWithBalance(donor);46        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');47        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);48        let resutl = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});49        expect(resutl.events).to.be.like({50            CollectionDestroyed: {51                returnValues: {52                    collectionId: collectionAddress53                }54            }55        });56    });57    58    itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {59        const owner = await helper.eth.createAccountWithBalance(donor);60        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');61        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);62        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);63        64        {65            const events: any = [];66            collectionHelper.events.allEvents((_: any, event: any) => {67                events.push(event);68            });69            await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});70            expect(events).to.be.like([71                {72                    event: 'CollectionChanged',73                    returnValues: {74                        collectionId: collectionAddress75                    }76                }77            ]);78        }79        {80            const events: any = [];81            collectionHelper.events.allEvents((_: any, event: any) => {82                events.push(event);83            });84            await collection.methods.deleteCollectionProperties(['A']).send({from:owner});85            expect(events).to.be.like([86                {87                    event: 'CollectionChanged',88                    returnValues: {89                        collectionId: collectionAddress90                    }91                }92            ]);93        }9495    });96    97    itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {98        const owner = await helper.eth.createAccountWithBalance(donor);99        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');100        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);101        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);102        const events: any = [];103        collectionHelper.events.allEvents((_: any, event: any) => {104            events.push(event);105        });106        await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});107        expect(events).to.be.like([108            {109                event: 'CollectionChanged',110                returnValues: {111                    collectionId: collectionAddress112                }113            }114        ]);115    });116    117    // itEth('CollectionChanged event for AllowListAddressAdded', async ({helper}) => {118    //     const owner = await helper.eth.createAccountWithBalance(donor);119    //     const user = await helper.eth.createAccount();120    //     const userCross = helper.ethCrossAccount.fromAddress(user);121    //     const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});122    //   // allow list does not need to be enabled to add someone in advance123    //     const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);124    //     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);125    //     const events: any = [];126    //     collectionHelper.events.allEvents((_: any, event: any) => {127    //         events.push(event);128    //     });129    //     await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});130    //     expect(events).to.be.like([131    //         {132    //             event: 'CollectionChanged',133    //             returnValues: {134    //                 collectionId: collectionAddress135    //             }136    //         }137    //     ]);138    // });139});