From 6b02c7807444c02b60df02f114cd9d428b73a92f Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 9 Oct 2024 13:47:21 +0300 Subject: [PATCH 1/2] Add new events support to refresh cache when changes happen --- src/modules/assets/models/AuctionEvent.enum.ts | 3 +++ .../blockchain-events/nft-events.service.ts | 18 +++++++++++++++++- .../elastic-updates-events.consumer.ts | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/modules/assets/models/AuctionEvent.enum.ts b/src/modules/assets/models/AuctionEvent.enum.ts index 139b5c4bd..ddb7ad3ca 100644 --- a/src/modules/assets/models/AuctionEvent.enum.ts +++ b/src/modules/assets/models/AuctionEvent.enum.ts @@ -49,6 +49,9 @@ export enum NftEventEnum { ESDTNFTCreate = 'ESDTNFTCreate', ESDTNFTBurn = 'ESDTNFTBurn', ESDTNFTUpdateAttributes = 'ESDTNFTUpdateAttributes', + ESDTMetaDataUpdate = 'ESDTMetaDataUpdate', + ESDTMetaDataRecreate = 'ESDTMetaDataRecreate', + ESDTModifyCreator = 'ESDTModifyCreator', } export enum NftEventTypeEnum { diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.service.ts b/src/modules/rabbitmq/blockchain-events/nft-events.service.ts index 58d0b05eb..2ec6cb1a3 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.service.ts @@ -7,6 +7,7 @@ import { MintEvent } from '../entities/auction/mint.event'; import { MultiTransferEvent, TransferEvent } from '../entities/auction/transfer.event'; import { FeedEventsSenderService } from './feed-events.service'; import { BurnEvent } from '../entities/auction/burn.event'; +import { UpdateAttributesEvent } from '../entities/auction/update-attributes.event'; @Injectable() export class NftEventsService { @@ -14,7 +15,7 @@ export class NftEventsService { private feedEventsSenderService: FeedEventsSenderService, private mxApiService: MxApiService, private readonly cacheEventsPublisherService: CacheEventsPublisherService, - ) {} + ) { } public async handleNftMintEvents(mintEvents: any[], hash: string) { for (let event of mintEvents) { @@ -71,8 +72,23 @@ export class NftEventsService { } } } + break; + case NftEventEnum.ESDTModifyCreator: + case NftEventEnum.ESDTMetaDataRecreate: + case NftEventEnum.ESDTMetaDataUpdate: + case NftEventEnum.ESDTNFTUpdateAttributes: + const updateEvent = new UpdateAttributesEvent(event); + const updateTopics = updateEvent.getTopics(); + const collectionUpdateInfo = await this.mxApiService.getCollectionByIdentifierForQuery(updateTopics.collection, 'fields=name,type'); + if (collectionUpdateInfo?.type === NftTypeEnum.NonFungibleESDT || collectionUpdateInfo?.type === NftTypeEnum.SemiFungibleESDT) { + await this.triggerCacheInvalidation( + `${updateTopics.collection}-${updateTopics.nonce}`, + CacheEventTypeEnum.AssetRefresh, + ); + } break; + } } } diff --git a/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts b/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts index 849b11f26..d75b9ce5f 100644 --- a/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts +++ b/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts @@ -5,7 +5,7 @@ import { ElasticUpdatesEventsService } from './elastic-updates-events.service'; @Injectable() export class ElasiticUpdatesConsumer { - constructor(private readonly elasticUpdateService: ElasticUpdatesEventsService) {} + constructor(private readonly elasticUpdateService: ElasticUpdatesEventsService) { } @CompetingRabbitConsumer({ connection: 'default', @@ -18,7 +18,7 @@ export class ElasiticUpdatesConsumer { const mintNftEvents = events?.events?.filter((e: { identifier: NftEventEnum }) => e.identifier === NftEventEnum.ESDTNFTCreate); const burnAndUpdateNftAttributesEvents = events?.events?.filter( (e: { identifier: NftEventEnum }) => - e.identifier === NftEventEnum.ESDTNFTBurn || e.identifier === NftEventEnum.ESDTNFTUpdateAttributes, + e.identifier === NftEventEnum.ESDTNFTBurn || e.identifier === NftEventEnum.ESDTNFTUpdateAttributes || e.identifier === NftEventEnum.ESDTMetaDataUpdate || e.identifier === NftEventEnum.ESDTMetaDataRecreate, ); const mintBurnAndUpdateNftAttributesEvents = [...mintNftEvents, ...burnAndUpdateNftAttributesEvents]; From fc6a316afa960af92aa21bdd4e2ac71efd4707b5 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 9 Oct 2024 16:05:17 +0300 Subject: [PATCH 2/2] Extract array of events --- .../elastic-updates/elastic-updates-events.consumer.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts b/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts index d75b9ce5f..d1e0a3270 100644 --- a/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts +++ b/src/modules/rabbitmq/elastic-updates/elastic-updates-events.consumer.ts @@ -14,12 +14,11 @@ export class ElasiticUpdatesConsumer { dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE, }) async consumeMintBurnAndUpdateEvents(events: any) { + const updateEvents = [NftEventEnum.ESDTNFTBurn, NftEventEnum.ESDTNFTUpdateAttributes, NftEventEnum.ESDTMetaDataUpdate, NftEventEnum.ESDTMetaDataRecreate,] if (events.events && process.env.ENABLE_ELASTIC_UPDATES === 'true') { const mintNftEvents = events?.events?.filter((e: { identifier: NftEventEnum }) => e.identifier === NftEventEnum.ESDTNFTCreate); const burnAndUpdateNftAttributesEvents = events?.events?.filter( - (e: { identifier: NftEventEnum }) => - e.identifier === NftEventEnum.ESDTNFTBurn || e.identifier === NftEventEnum.ESDTNFTUpdateAttributes || e.identifier === NftEventEnum.ESDTMetaDataUpdate || e.identifier === NftEventEnum.ESDTMetaDataRecreate, - ); + (e: { identifier: NftEventEnum }) => updateEvents.includes(e.identifier)); const mintBurnAndUpdateNftAttributesEvents = [...mintNftEvents, ...burnAndUpdateNftAttributesEvents]; await Promise.all([