Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new events support to refresh cache when changes happen #1084

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/modules/assets/models/AuctionEvent.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export enum NftEventEnum {
ESDTNFTCreate = 'ESDTNFTCreate',
ESDTNFTBurn = 'ESDTNFTBurn',
ESDTNFTUpdateAttributes = 'ESDTNFTUpdateAttributes',
ESDTMetaDataUpdate = 'ESDTMetaDataUpdate',
ESDTMetaDataRecreate = 'ESDTMetaDataRecreate',
ESDTModifyCreator = 'ESDTModifyCreator',
}

export enum NftEventTypeEnum {
Expand Down
18 changes: 17 additions & 1 deletion src/modules/rabbitmq/blockchain-events/nft-events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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 {
constructor(
private feedEventsSenderService: FeedEventsSenderService,
private mxApiService: MxApiService,
private readonly cacheEventsPublisherService: CacheEventsPublisherService,
) {}
) { }

public async handleNftMintEvents(mintEvents: any[], hash: string) {
for (let event of mintEvents) {
Expand Down Expand Up @@ -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}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check: nonce is here as hex (not number), correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

CacheEventTypeEnum.AssetRefresh,
);
}
break;

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 }) => updateEvents.includes(e.identifier));
const mintBurnAndUpdateNftAttributesEvents = [...mintNftEvents, ...burnAndUpdateNftAttributesEvents];

await Promise.all([
Expand Down
Loading