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.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.tsdiffbeforeafterboth1// 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 { expect } from 'chai';18import {IKeyringPair} from '@polkadot/types/types';19import { itEth, usingEthPlaygrounds } from './util';2021describe('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 {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated']}]);33 const {collectionAddress, events: ethEvents} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');34 expect(ethEvents).to.be.like([35 {36 event: 'CollectionCreated',37 args: {38 owner: owner,39 collectionId: collectionAddress40 }41 }42 ]);43 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);44 unsubscribe();45 });4647 itEth('Destroy event', async ({helper}) => {48 const owner = await helper.eth.createAccountWithBalance(donor);49 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');50 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);51 const {unsubscribe, collectedEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionDestroyed']}]);52 let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});53 expect(result.events).to.be.like({54 CollectionDestroyed: {55 returnValues: {56 collectionId: collectionAddress57 }58 }59 });60 expect(collectedEvents).to.be.like([{method: 'CollectionDestroyed'}]);61 unsubscribe();62 });63 64 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {65 const owner = await helper.eth.createAccountWithBalance(donor);66 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');67 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);68 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);69 70 let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);71 {72 const ethEvents: any = [];73 collectionHelper.events.allEvents((_: any, event: any) => {74 ethEvents.push(event);75 });76 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});77 expect(ethEvents).to.be.like([78 {79 event: 'CollectionChanged',80 returnValues: {81 collectionId: collectionAddress82 }83 }84 ]);85 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);86 subEvents.pop();87 }88 {89 const ethEvents: any = [];90 collectionHelper.events.allEvents((_: any, event: any) => {91 ethEvents.push(event);92 });93 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});94 expect(ethEvents).to.be.like([95 {96 event: 'CollectionChanged',97 returnValues: {98 collectionId: collectionAddress99 }100 }101 ]);102 expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);103 }104 unsubscribe();105 });106 107 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {108 const owner = await helper.eth.createAccountWithBalance(donor);109 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');110 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);111 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);112 const eethEvents: any = [];113 collectionHelper.events.allEvents((_: any, event: any) => {114 eethEvents.push(event);115 });116 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);117 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});118 expect(eethEvents).to.be.like([119 {120 event: 'CollectionChanged',121 returnValues: {122 collectionId: collectionAddress123 }124 }125 ]);126 expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);127 unsubscribe();128 });129 130 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {131 const owner = await helper.eth.createAccountWithBalance(donor);132 const user = helper.ethCrossAccount.createAccount();133 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');134 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);135 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);136 const ethEvents: any[] = [];137 collectionHelper.events.allEvents((_: any, event: any) => {138 ethEvents.push(event);139 });140141 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['AllowListAddressAdded', 'AllowListAddressRemoved']}]);142 {143 await collection.methods.addToCollectionAllowListCross(user).send({from: owner});144 expect(ethEvents).to.be.like([145 {146 event: 'CollectionChanged',147 returnValues: {148 collectionId: collectionAddress149 }150 }151 ]);152 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);153 ethEvents.pop();154 subEvents.pop();155 }156 {157 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});158 expect(ethEvents.length).to.be.eq(1);159 expect(ethEvents).to.be.like([160 {161 event: 'CollectionChanged',162 returnValues: {163 collectionId: collectionAddress164 }165 }166 ]);167 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);168 }169 unsubscribe();170 });171 172 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {173 const owner = await helper.eth.createAccountWithBalance(donor);174 const user = helper.ethCrossAccount.createAccount();175 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');176 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);177 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);178 const ethEvents: any = [];179 collectionHelper.events.allEvents((_: any, event: any) => {180 ethEvents.push(event);181 });182 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]);183 {184 await collection.methods.addCollectionAdminCross(user).send({from: owner});185 expect(ethEvents).to.be.like([186 {187 event: 'CollectionChanged',188 returnValues: {189 collectionId: collectionAddress190 }191 }192 ]);193 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);194 ethEvents.pop();195 subEvents.pop();196 }197 {198 await collection.methods.removeCollectionAdminCross(user).send({from: owner});199 expect(ethEvents).to.be.like([200 {201 event: 'CollectionChanged',202 returnValues: {203 collectionId: collectionAddress204 }205 }206 ]);207 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);208 }209 unsubscribe();210 });211 212 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {213 const owner = await helper.eth.createAccountWithBalance(donor);214 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');215 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);216 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);217 const ethEvents: any = [];218 collectionHelper.events.allEvents((_: any, event: any) => {219 ethEvents.push(event);220 });221 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]);222 {223 await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});224 expect(ethEvents).to.be.like([225 {226 event: 'CollectionChanged',227 returnValues: {228 collectionId: collectionAddress229 }230 }231 ]);232 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);233 }234 unsubscribe();235 });236 237 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {238 const owner = await helper.eth.createAccountWithBalance(donor);239 const new_owner = helper.ethCrossAccount.createAccount();240 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');241 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);242 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);243 const ethEvents: any = [];244 collectionHelper.events.allEvents((_: any, event: any) => {245 ethEvents.push(event);246 });247 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]);248 {249 await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});250 expect(ethEvents).to.be.like([251 {252 event: 'CollectionChanged',253 returnValues: {254 collectionId: collectionAddress255 }256 }257 ]);258 expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);259 }260 unsubscribe();261 });262 263 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {264 const owner = await helper.eth.createAccountWithBalance(donor);265 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');266 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);267 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);268 const ethEvents: any = [];269 collectionHelper.events.allEvents((_: any, event: any) => {270 ethEvents.push(event);271 });272 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]);273 {274 await collection.methods.setCollectionMintMode(true).send({from: owner});275 expect(ethEvents).to.be.like([276 {277 event: 'CollectionChanged',278 returnValues: {279 collectionId: collectionAddress280 }281 }282 ]);283 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);284 ethEvents.pop();285 subEvents.pop();286 }287 {288 await collection.methods.setCollectionAccess(1).send({from: owner});289 expect(ethEvents).to.be.like([290 {291 event: 'CollectionChanged',292 returnValues: {293 collectionId: collectionAddress294 }295 }296 ]);297 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);298 }299 unsubscribe();300 });301302 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {303 const owner = await helper.eth.createAccountWithBalance(donor);304 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);305 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');306 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);307 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);308 const ethEvents: any = [];309 collectionHelper.events.allEvents((_: any, event: any) => {310 ethEvents.push(event);311 });312 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{313 section: 'common', names: ['CollectionSponsorSet', 'SponsorshipConfirmed', 'CollectionSponsorRemoved'314 ]}]);315 {316 await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});317 expect(ethEvents).to.be.like([318 {319 event: 'CollectionChanged',320 returnValues: {321 collectionId: collectionAddress322 }323 }324 ]);325 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);326 ethEvents.pop();327 subEvents.pop();328 }329 {330 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});331 expect(ethEvents).to.be.like([332 {333 event: 'CollectionChanged',334 returnValues: {335 collectionId: collectionAddress336 }337 }338 ]);339 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);340 ethEvents.pop();341 subEvents.pop();342 }343 {344 await collection.methods.removeCollectionSponsor().send({from: owner});345 expect(ethEvents).to.be.like([346 {347 event: 'CollectionChanged',348 returnValues: {349 collectionId: collectionAddress350 }351 }352 ]);353 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);354 }355 unsubscribe();356 });357 358});