From e52149d191dcf2f0f90ef0fb2332814bce17b7e3 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 Nov 2023 14:32:39 +0200 Subject: [PATCH 01/25] Add marketplace state --- src/db/marketplaces/marketplace.entity.ts | 5 ++++- .../marketplaces/marketplaces.repository.ts | 1 + .../1700656065946-AddMarketplaceState.ts | 13 ++++++++++++ .../marketplaces/marketplaces.service.ts | 21 ++++++++++++++----- .../marketplaces/models/Marketplace.dto.ts | 6 +++++- .../models/MarketplaceType.enum.ts | 8 +++++++ .../disable-marketplace-events.service.ts | 11 ++++++++++ .../blockchain-events/nft-events.consumer.ts | 7 +++++++ .../blockchain-events/nft-events.module.ts | 2 ++ .../change-events-publisher.service.ts | 9 ++++++++ src/modules/rabbitmq/rabbit-config.ts | 1 + 11 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/db/migrations/1700656065946-AddMarketplaceState.ts create mode 100644 src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts diff --git a/src/db/marketplaces/marketplace.entity.ts b/src/db/marketplaces/marketplace.entity.ts index fc3c12847..ad521c19d 100644 --- a/src/db/marketplaces/marketplace.entity.ts +++ b/src/db/marketplaces/marketplace.entity.ts @@ -1,4 +1,4 @@ -import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { MarketplaceState, MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; import { Column, Entity, Index, JoinTable, ManyToMany } from 'typeorm'; import { BaseEntity } from '../base-entity'; import { MarketplaceCollectionEntity } from './marketplace-collection.entity'; @@ -12,6 +12,9 @@ export class MarketplaceEntity extends BaseEntity { @Column({ length: 62 }) name: string; + @Column({ type: 'bit' }) + state: MarketplaceState; + @Column({ length: 62, unique: true }) key: string; diff --git a/src/db/marketplaces/marketplaces.repository.ts b/src/db/marketplaces/marketplaces.repository.ts index 43e8fe497..b48084933 100644 --- a/src/db/marketplaces/marketplaces.repository.ts +++ b/src/db/marketplaces/marketplaces.repository.ts @@ -35,6 +35,7 @@ export class MarketplaceRepository { .addSelect('fm.url as url') .addSelect('fm.name as name') .addSelect('fm.key as `key`') + .addSelect('fm.state as state') .where('fm.address IN(:...addresses)', { addresses: addresses, }) diff --git a/src/db/migrations/1700656065946-AddMarketplaceState.ts b/src/db/migrations/1700656065946-AddMarketplaceState.ts new file mode 100644 index 000000000..cf0b8d2ff --- /dev/null +++ b/src/db/migrations/1700656065946-AddMarketplaceState.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddMarketplaceState1700656065946 implements MigrationInterface { + name = 'AddMarketplaceState1700656065946'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` bit NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`marketplaces\` DROP COLUMN \`state\``); + } +} diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index df1f74f71..3ca533a0e 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -4,7 +4,7 @@ import { CollectionType } from '../assets/models/Collection.type'; import { Marketplace } from './models'; import { MarketplacesCachingService } from './marketplaces-caching.service'; import { MarketplaceCollectionEntity, MarketplaceEntity } from 'src/db/marketplaces'; -import { MarketplaceTypeEnum } from './models/MarketplaceType.enum'; +import { MarketplaceState, MarketplaceTypeEnum } from './models/MarketplaceType.enum'; import { MarketplaceFilters } from './models/Marketplace.Filter'; import { PersistenceService } from 'src/common/persistence/persistence.service'; import { RemoveWhitelistCollectionRequest, WhitelistCollectionRequest } from './models/requests/WhitelistCollectionOnMarketplaceRequest'; @@ -75,11 +75,20 @@ export class MarketplacesService { async getExternalMarketplacesAddreses(): Promise { let allMarketplaces = await this.getAllMarketplaces(); - const externalMarketplaces = allMarketplaces?.items?.filter((m) => m.type === MarketplaceTypeEnum.External); + const externalMarketplaces = allMarketplaces?.items?.filter( + (m) => m.type === MarketplaceTypeEnum.External && m.state === MarketplaceState.Enable, + ); return externalMarketplaces.map((m) => m.address); } + async getDisableMarketplacesAddreses(): Promise { + let allMarketplaces = await this.getAllMarketplaces(); + + const externalMarketplaces = allMarketplaces?.items?.filter((m) => m.state === MarketplaceState.Disable); + + return externalMarketplaces.map((m) => m.address); + } async getMarketplacesAddreses(): Promise { let allMarketplaces = await this.getAllMarketplaces(); @@ -131,15 +140,17 @@ export class MarketplacesService { private async getInternalMarketplaces(): Promise { const allMarketplaces = await this.getAllMarketplaces(); - const internalMarketplaces = allMarketplaces?.items?.filter((m) => m.type === MarketplaceTypeEnum.Internal); + const internalMarketplaces = allMarketplaces?.items?.filter( + (m) => m.type === MarketplaceTypeEnum.Internal && m.state === MarketplaceState.Enable, + ); return internalMarketplaces; } async getMarketplacesFromDb(): Promise> { - const [campaigns, count]: [MarketplaceEntity[], number] = await this.persistenceService.getMarketplaces(); + const [marketplaces, count]: [MarketplaceEntity[], number] = await this.persistenceService.getMarketplaces(); return new CollectionType({ count: count, - items: campaigns.map((campaign) => Marketplace.fromEntity(campaign)), + items: marketplaces.map((marketplace) => Marketplace.fromEntity(marketplace)), }); } diff --git a/src/modules/marketplaces/models/Marketplace.dto.ts b/src/modules/marketplaces/models/Marketplace.dto.ts index da477f605..79f7a2f05 100644 --- a/src/modules/marketplaces/models/Marketplace.dto.ts +++ b/src/modules/marketplaces/models/Marketplace.dto.ts @@ -5,7 +5,7 @@ import { NftTypeEnum } from 'src/modules/assets/models'; import { Token } from 'src/modules/usdPrice/Token.model'; import { DEADRARE_KEY, ELRONDNFTSWAP_KEY, FRAMEIT_KEY, ICI_KEY, XOXNO_KEY } from 'src/utils/constants'; import { getCollectionAndNonceFromIdentifier } from 'src/utils/helpers'; -import { MarketplaceTypeEnum } from './MarketplaceType.enum'; +import { MarketplaceState, MarketplaceTypeEnum } from './MarketplaceType.enum'; @ObjectType() export class Marketplace { id: number; @@ -28,6 +28,9 @@ export class Marketplace { @Field(() => MarketplaceTypeEnum) type: MarketplaceTypeEnum; + @Field(() => MarketplaceState) + state: MarketplaceState; + @Field({ nullable: true }) marketplaceCutPercentage: string; @@ -62,6 +65,7 @@ export class Marketplace { key: entity.key, type: entity.type, lastIndexTimestamp: entity.lastIndexTimestamp, + state: entity.state, }); } diff --git a/src/modules/marketplaces/models/MarketplaceType.enum.ts b/src/modules/marketplaces/models/MarketplaceType.enum.ts index 7ad4f8396..572b8fca4 100644 --- a/src/modules/marketplaces/models/MarketplaceType.enum.ts +++ b/src/modules/marketplaces/models/MarketplaceType.enum.ts @@ -7,3 +7,11 @@ export enum MarketplaceTypeEnum { registerEnumType(MarketplaceTypeEnum, { name: 'MarketplaceTypeEnum', }); + +export enum MarketplaceState { + Enable, + Disable, +} +registerEnumType(MarketplaceState, { + name: 'MarketplaceState', +}); diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts new file mode 100644 index 000000000..70cc91ccd --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts @@ -0,0 +1,11 @@ +import { Injectable } from '@nestjs/common'; +import { MarketplaceDisablePublisherService } from '../cache-invalidation/cache-invalidation-publisher/change-events-publisher.service'; + +@Injectable() +export class DisabledMarketplaceEventsService { + constructor(private disabledMarketplacePublisherService: MarketplaceDisablePublisherService) {} + + public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { + await this.disabledMarketplacePublisherService.publish({ hash: hash, events: auctionEvents }); + } +} diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index 250acde90..c86e590c8 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -10,6 +10,7 @@ import { MinterEventsService } from './minter-events.service'; import { NftEventsService } from './nft-events.service'; import { AnalyticsEventsService } from './analytics-events.service'; import { MintersService } from 'src/modules/minters/minters.service'; +import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; @Injectable() export class NftEventsConsumer { @@ -22,6 +23,7 @@ export class NftEventsConsumer { private readonly marketplaceService: MarketplacesService, private readonly mintersService: MintersService, private readonly analyticsEventsService: AnalyticsEventsService, + private readonly disabledMarketplaceService: DisabledMarketplaceEventsService, ) {} @CompetingRabbitConsumer({ @@ -34,7 +36,11 @@ export class NftEventsConsumer { if (nftAuctionEvents?.events) { const internalMarketplaces = await this.marketplaceService.getInternalMarketplacesAddreses(); const externalMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); + const disabledMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); + const disabledMarketplacesEvents = nftAuctionEvents?.events?.filter( + (e: { address: any }) => disabledMarketplaces.includes(e.address) === true, + ); const internalMarketplaceEvents = nftAuctionEvents?.events?.filter( (e: { address: any }) => internalMarketplaces.includes(e.address) === true, ); @@ -63,6 +69,7 @@ export class NftEventsConsumer { nftAuctionEvents.hash, MarketplaceTypeEnum.External, ); + await this.disabledMarketplaceService.handleAuctionEventsForDisableMarketplace(disabledMarketplacesEvents, nftAuctionEvents.hash); await this.minterEventsService.handleNftMinterEvents( nftAuctionEvents?.events?.filter((e: { address: any }) => minters?.includes(e.address) === true), nftAuctionEvents.hash, diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index 44ca983d7..80ab187e3 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -45,6 +45,7 @@ import { PluginModule } from 'src/plugins/plugin.module'; import { AnalyticsEventsService } from './analytics-events.service'; import { AnalyticsModule } from 'src/modules/analytics/analytics.module'; import { MintersModuleGraph } from 'src/modules/minters/minters.module'; +import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; @Module({ imports: [ @@ -97,6 +98,7 @@ import { MintersModuleGraph } from 'src/modules/minters/minters.module'; FeedEventsSenderService, UsdPriceService, AnalyticsEventsService, + DisabledMarketplaceEventsService, ], exports: [NftEventsService], }) diff --git a/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts b/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts index 075b3c337..ff12da370 100644 --- a/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts +++ b/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts @@ -21,3 +21,12 @@ export class NftLikePublisherService { await this.rabbitPublisherService.publish(rabbitExchanges.NFT_LIKE, payload); } } + +@Injectable() +export class MarketplaceDisablePublisherService { + constructor(private readonly rabbitPublisherService: RabbitPublisherService) {} + + async publish(payload: any) { + await this.rabbitPublisherService.publish(rabbitExchanges.DISABLE_MARKETPLACE_EVENTS, payload); + } +} diff --git a/src/modules/rabbitmq/rabbit-config.ts b/src/modules/rabbitmq/rabbit-config.ts index c6a5f890a..0338f7c32 100644 --- a/src/modules/rabbitmq/rabbit-config.ts +++ b/src/modules/rabbitmq/rabbit-config.ts @@ -14,6 +14,7 @@ export interface RabbitModuleConfig { export const rabbitExchanges = { CACHE_INVALIDATION: 'nft-cache-invalidation', NFT_LIKE: 'x_portal_gamification_nft_likes_exchange', + DISABLE_MARKETPLACE_EVENTS: 'marketplace', }; export const rabbitQueues = { From 5ed99c618d0fffe08943dad00a1990023e00d551 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 Nov 2023 15:30:05 +0200 Subject: [PATCH 02/25] Upgrade marketplace state migration --- schema.gql | 6 ++++++ src/db/marketplaces/marketplace.entity.ts | 2 +- ...etplaceState.ts => 1700659694771-AddMarketplaceState.ts} | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) rename src/db/migrations/{1700656065946-AddMarketplaceState.ts => 1700659694771-AddMarketplaceState.ts} (72%) diff --git a/schema.gql b/schema.gql index 2529f0127..31d5a1755 100644 --- a/schema.gql +++ b/schema.gql @@ -830,6 +830,7 @@ type Marketplace { key: ID! marketplaceCutPercentage: String name: String! + state: MarketplaceState! type: MarketplaceTypeEnum! url: String! } @@ -870,6 +871,11 @@ input MarketplaceReindexDataArgs { marketplaceAddress: String! } +enum MarketplaceState { + Disable + Enable +} + enum MarketplaceTypeEnum { External Internal diff --git a/src/db/marketplaces/marketplace.entity.ts b/src/db/marketplaces/marketplace.entity.ts index ad521c19d..3d5bc10fc 100644 --- a/src/db/marketplaces/marketplace.entity.ts +++ b/src/db/marketplaces/marketplace.entity.ts @@ -12,7 +12,7 @@ export class MarketplaceEntity extends BaseEntity { @Column({ length: 62 }) name: string; - @Column({ type: 'bit' }) + @Column({ type: 'tinyint' }) state: MarketplaceState; @Column({ length: 62, unique: true }) diff --git a/src/db/migrations/1700656065946-AddMarketplaceState.ts b/src/db/migrations/1700659694771-AddMarketplaceState.ts similarity index 72% rename from src/db/migrations/1700656065946-AddMarketplaceState.ts rename to src/db/migrations/1700659694771-AddMarketplaceState.ts index cf0b8d2ff..43c31301e 100644 --- a/src/db/migrations/1700656065946-AddMarketplaceState.ts +++ b/src/db/migrations/1700659694771-AddMarketplaceState.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -export class AddMarketplaceState1700656065946 implements MigrationInterface { - name = 'AddMarketplaceState1700656065946'; +export class AddMarketplaceState1700659694771 implements MigrationInterface { + name = 'AddMarketplaceState1700659694771'; public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` bit NOT NULL`); + await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` tinyint NOT NULL`); } public async down(queryRunner: QueryRunner): Promise { From a510c6c3395bc8d6c898668052035968b0162771 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 Nov 2023 15:45:27 +0200 Subject: [PATCH 03/25] Update migration --- src/db/marketplaces/marketplace.entity.ts | 2 +- src/db/marketplaces/marketplaces.repository.ts | 2 +- ...etplaceState.ts => 1700660634671-AddMarketplaceState.ts} | 6 +++--- src/modules/marketplaces/models/MarketplaceType.enum.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/db/migrations/{1700659694771-AddMarketplaceState.ts => 1700660634671-AddMarketplaceState.ts} (71%) diff --git a/src/db/marketplaces/marketplace.entity.ts b/src/db/marketplaces/marketplace.entity.ts index 3d5bc10fc..3bf91a69a 100644 --- a/src/db/marketplaces/marketplace.entity.ts +++ b/src/db/marketplaces/marketplace.entity.ts @@ -12,7 +12,7 @@ export class MarketplaceEntity extends BaseEntity { @Column({ length: 62 }) name: string; - @Column({ type: 'tinyint' }) + @Column({ length: 10 }) state: MarketplaceState; @Column({ length: 62, unique: true }) diff --git a/src/db/marketplaces/marketplaces.repository.ts b/src/db/marketplaces/marketplaces.repository.ts index b48084933..d11edc9f1 100644 --- a/src/db/marketplaces/marketplaces.repository.ts +++ b/src/db/marketplaces/marketplaces.repository.ts @@ -35,7 +35,7 @@ export class MarketplaceRepository { .addSelect('fm.url as url') .addSelect('fm.name as name') .addSelect('fm.key as `key`') - .addSelect('fm.state as state') + .addSelect('fm.state as `state`') .where('fm.address IN(:...addresses)', { addresses: addresses, }) diff --git a/src/db/migrations/1700659694771-AddMarketplaceState.ts b/src/db/migrations/1700660634671-AddMarketplaceState.ts similarity index 71% rename from src/db/migrations/1700659694771-AddMarketplaceState.ts rename to src/db/migrations/1700660634671-AddMarketplaceState.ts index 43c31301e..c7187687b 100644 --- a/src/db/migrations/1700659694771-AddMarketplaceState.ts +++ b/src/db/migrations/1700660634671-AddMarketplaceState.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -export class AddMarketplaceState1700659694771 implements MigrationInterface { - name = 'AddMarketplaceState1700659694771'; +export class AddMarketplaceState1700660634671 implements MigrationInterface { + name = 'AddMarketplaceState1700660634671'; public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` tinyint NOT NULL`); + await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` varchar(10) NOT NULL`); } public async down(queryRunner: QueryRunner): Promise { diff --git a/src/modules/marketplaces/models/MarketplaceType.enum.ts b/src/modules/marketplaces/models/MarketplaceType.enum.ts index 572b8fca4..eb8e121e2 100644 --- a/src/modules/marketplaces/models/MarketplaceType.enum.ts +++ b/src/modules/marketplaces/models/MarketplaceType.enum.ts @@ -9,8 +9,8 @@ registerEnumType(MarketplaceTypeEnum, { }); export enum MarketplaceState { - Enable, - Disable, + Enable = 'Enable', + Disable = 'Disable', } registerEnumType(MarketplaceState, { name: 'MarketplaceState', From 92ac4a0e558118d26694146df1766576e0452d66 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 Nov 2023 16:24:30 +0200 Subject: [PATCH 04/25] Update disable processing --- .../marketplaces/change-events-publisher.service.ts | 12 ++++++++++++ .../disable-marketplace-events.service.ts | 2 +- .../rabbitmq/blockchain-events/nft-events.module.ts | 4 ++++ .../change-events-publisher.service.ts | 9 --------- 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 src/modules/marketplaces/change-events-publisher.service.ts diff --git a/src/modules/marketplaces/change-events-publisher.service.ts b/src/modules/marketplaces/change-events-publisher.service.ts new file mode 100644 index 000000000..f8e7ac6cb --- /dev/null +++ b/src/modules/marketplaces/change-events-publisher.service.ts @@ -0,0 +1,12 @@ +import { Injectable } from '@nestjs/common'; +import { rabbitExchanges } from '../rabbitmq/rabbit-config'; +import { RabbitPublisherService } from '../rabbitmq/rabbit.publisher'; + +@Injectable() +export class MarketplaceDisablePublisherService { + constructor(private readonly rabbitPublisherService: RabbitPublisherService) {} + + async publish(payload: any) { + await this.rabbitPublisherService.publish(rabbitExchanges.DISABLE_MARKETPLACE_EVENTS, payload); + } +} diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts index 70cc91ccd..1576e3ca5 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { MarketplaceDisablePublisherService } from '../cache-invalidation/cache-invalidation-publisher/change-events-publisher.service'; +import { MarketplaceDisablePublisherService } from 'src/modules/marketplaces/change-events-publisher.service'; @Injectable() export class DisabledMarketplaceEventsService { diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index 80ab187e3..317617418 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -46,6 +46,8 @@ import { AnalyticsEventsService } from './analytics-events.service'; import { AnalyticsModule } from 'src/modules/analytics/analytics.module'; import { MintersModuleGraph } from 'src/modules/minters/minters.module'; import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; +import { MarketplaceDisablePublisherService } from 'src/modules/marketplaces/change-events-publisher.service'; +import { RabbitPublisherService } from '../rabbit.publisher'; @Module({ imports: [ @@ -99,6 +101,8 @@ import { DisabledMarketplaceEventsService } from './disable-marketplace-events.s UsdPriceService, AnalyticsEventsService, DisabledMarketplaceEventsService, + MarketplaceDisablePublisherService, + RabbitPublisherService, ], exports: [NftEventsService], }) diff --git a/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts b/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts index ff12da370..075b3c337 100644 --- a/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts +++ b/src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service.ts @@ -21,12 +21,3 @@ export class NftLikePublisherService { await this.rabbitPublisherService.publish(rabbitExchanges.NFT_LIKE, payload); } } - -@Injectable() -export class MarketplaceDisablePublisherService { - constructor(private readonly rabbitPublisherService: RabbitPublisherService) {} - - async publish(payload: any) { - await this.rabbitPublisherService.publish(rabbitExchanges.DISABLE_MARKETPLACE_EVENTS, payload); - } -} From 05e71855af98b052f1a48e754740147c5e34ddbf Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 12:17:14 +0200 Subject: [PATCH 05/25] Update rabbit dependencies --- .../rabbitmq/blockchain-events/nft-events.consumer.ts | 2 +- .../rabbitmq/blockchain-events/nft-events.module.ts | 8 ++------ src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts | 7 ++++++- .../disable-marketplace-events.service.ts | 2 +- .../disable-marketplace-publisher.service.ts} | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) rename src/modules/rabbitmq/{blockchain-events => }/disable-marketplace-events.service.ts (78%) rename src/modules/{marketplaces/change-events-publisher.service.ts => rabbitmq/disable-marketplace-publisher.service.ts} (71%) diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index c86e590c8..e378f064c 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -10,7 +10,7 @@ import { MinterEventsService } from './minter-events.service'; import { NftEventsService } from './nft-events.service'; import { AnalyticsEventsService } from './analytics-events.service'; import { MintersService } from 'src/modules/minters/minters.service'; -import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; +import { DisabledMarketplaceEventsService } from '../disable-marketplace-events.service'; @Injectable() export class NftEventsConsumer { diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index 317617418..b4d9f9052 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -45,13 +45,12 @@ import { PluginModule } from 'src/plugins/plugin.module'; import { AnalyticsEventsService } from './analytics-events.service'; import { AnalyticsModule } from 'src/modules/analytics/analytics.module'; import { MintersModuleGraph } from 'src/modules/minters/minters.module'; -import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; -import { MarketplaceDisablePublisherService } from 'src/modules/marketplaces/change-events-publisher.service'; -import { RabbitPublisherService } from '../rabbit.publisher'; +import { RabbitMqModule } from './rabbitmq.module'; @Module({ imports: [ CommonModule, + forwardRef(() => RabbitMqModule.register()), CacheEventsPublisherModule, forwardRef(() => AuctionsModuleGraph), forwardRef(() => CampaignsModuleGraph), @@ -100,9 +99,6 @@ import { RabbitPublisherService } from '../rabbit.publisher'; FeedEventsSenderService, UsdPriceService, AnalyticsEventsService, - DisabledMarketplaceEventsService, - MarketplaceDisablePublisherService, - RabbitPublisherService, ], exports: [NftEventsService], }) diff --git a/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts b/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts index ff1defce1..a6d295663 100644 --- a/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts +++ b/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts @@ -1,6 +1,9 @@ import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; -import { DynamicModule, Module } from '@nestjs/common'; +import { DynamicModule, Module, forwardRef } from '@nestjs/common'; import { NftEventsModule } from './nft-events.module'; +import { RabbitPublisherService } from '../rabbit.publisher'; +import { DisabledMarketplaceEventsService } from '../disable-marketplace-events.service'; +import { MarketplaceDisablePublisherService } from '../disable-marketplace-publisher.service'; @Module({}) export class RabbitMqModule { @@ -28,6 +31,8 @@ export class RabbitMqModule { }, }), ], + providers: [RabbitPublisherService, DisabledMarketplaceEventsService, MarketplaceDisablePublisherService], + exports: [RabbitPublisherService, DisabledMarketplaceEventsService, MarketplaceDisablePublisherService], }; } } diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts b/src/modules/rabbitmq/disable-marketplace-events.service.ts similarity index 78% rename from src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts rename to src/modules/rabbitmq/disable-marketplace-events.service.ts index 1576e3ca5..3ccea29fc 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/disable-marketplace-events.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { MarketplaceDisablePublisherService } from 'src/modules/marketplaces/change-events-publisher.service'; +import { MarketplaceDisablePublisherService } from './disable-marketplace-publisher.service'; @Injectable() export class DisabledMarketplaceEventsService { diff --git a/src/modules/marketplaces/change-events-publisher.service.ts b/src/modules/rabbitmq/disable-marketplace-publisher.service.ts similarity index 71% rename from src/modules/marketplaces/change-events-publisher.service.ts rename to src/modules/rabbitmq/disable-marketplace-publisher.service.ts index f8e7ac6cb..1f291da66 100644 --- a/src/modules/marketplaces/change-events-publisher.service.ts +++ b/src/modules/rabbitmq/disable-marketplace-publisher.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; -import { rabbitExchanges } from '../rabbitmq/rabbit-config'; -import { RabbitPublisherService } from '../rabbitmq/rabbit.publisher'; +import { rabbitExchanges } from './rabbit-config'; +import { RabbitPublisherService } from './rabbit.publisher'; @Injectable() export class MarketplaceDisablePublisherService { From 46d097ef22ddfa727ed9d0bbf1c4000c3282de47 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 13:38:40 +0200 Subject: [PATCH 06/25] Add condition for marketplace events --- src/modules/rabbitmq/disable-marketplace-events.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/rabbitmq/disable-marketplace-events.service.ts b/src/modules/rabbitmq/disable-marketplace-events.service.ts index 3ccea29fc..8ea53112e 100644 --- a/src/modules/rabbitmq/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/disable-marketplace-events.service.ts @@ -6,6 +6,8 @@ export class DisabledMarketplaceEventsService { constructor(private disabledMarketplacePublisherService: MarketplaceDisablePublisherService) {} public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { - await this.disabledMarketplacePublisherService.publish({ hash: hash, events: auctionEvents }); + if (auctionEvents?.length) { + await this.disabledMarketplacePublisherService.publish({ hash: hash, events: auctionEvents }); + } } } From 7192ef32e3dc91c471403752ebbfac59c9174783 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 14:01:41 +0200 Subject: [PATCH 07/25] Add logging --- src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index e378f064c..1a827db40 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -38,9 +38,12 @@ export class NftEventsConsumer { const externalMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); const disabledMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); + console.log({ disabledMarketplaces: JSON.stringify(disabledMarketplaces) }); const disabledMarketplacesEvents = nftAuctionEvents?.events?.filter( (e: { address: any }) => disabledMarketplaces.includes(e.address) === true, ); + console.log({ disabledMarketplacesEvents: JSON.stringify(disabledMarketplacesEvents) }); + const internalMarketplaceEvents = nftAuctionEvents?.events?.filter( (e: { address: any }) => internalMarketplaces.includes(e.address) === true, ); From cb2b9461a7317ee3d315bb28c09a067c16b41e46 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 14:19:04 +0200 Subject: [PATCH 08/25] Update get Disable marketplace --- src/modules/marketplaces/marketplaces.service.ts | 1 + src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 3ca533a0e..8ff1e86d4 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -241,6 +241,7 @@ export class MarketplacesService { name: request.marketplaceName, url: request.marketplaceUrl, type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, }), ); diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index 1a827db40..a2eb27d15 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -36,7 +36,7 @@ export class NftEventsConsumer { if (nftAuctionEvents?.events) { const internalMarketplaces = await this.marketplaceService.getInternalMarketplacesAddreses(); const externalMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); - const disabledMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); + const disabledMarketplaces = await this.marketplaceService.getDisableMarketplacesAddreses(); console.log({ disabledMarketplaces: JSON.stringify(disabledMarketplaces) }); const disabledMarketplacesEvents = nftAuctionEvents?.events?.filter( From 5a74ef65df1fe3ff8bea97d27c33b1c157c7264d Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 15:07:34 +0200 Subject: [PATCH 09/25] Add endpoint to update marketplace state --- schema.gql | 7 +++++ src/common/persistence/persistence.service.ts | 8 ++++++ .../marketplaces/marketplaces.repository.ts | 8 ++++++ .../marketplaces-mutations.resolver.ts | 14 ++++++++++ .../marketplaces/marketplaces.service.ts | 26 +++++++++++++++++++ .../models/UpdateMarketplaceStateArgs.ts | 10 +++++++ 6 files changed, 73 insertions(+) create mode 100644 src/modules/marketplaces/models/UpdateMarketplaceStateArgs.ts diff --git a/schema.gql b/schema.gql index 31d5a1755..6d83c12a2 100644 --- a/schema.gql +++ b/schema.gql @@ -975,6 +975,8 @@ type Mutation { createNft(file: Upload!, input: CreateNftArgs!): TransactionNode! createNftWithMultipleFiles(files: [Upload!]!, input: CreateNftArgs!): TransactionNode! deployMinter(input: DeployMinterArgs!): TransactionNode! + disableMarketplace(input: UpdateMarketplaceStateArgs!): Boolean! + enableMarketplace(input: UpdateMarketplaceStateArgs!): Boolean! endAuction(auctionId: Int!): TransactionNode! flagCollection(input: FlagCollectionInput!): Boolean! flagNft(input: FlagNftInput!): Boolean! @@ -1500,6 +1502,11 @@ input UpdateMarketplaceArgs { marketplaceUrl: String } +input UpdateMarketplaceStateArgs { + """Smart Contract Address""" + marketplaceScAddress: String! +} + enum UpdateNftTraitsResponse { CollectionTraitsUpdated NftTraitsUpdated diff --git a/src/common/persistence/persistence.service.ts b/src/common/persistence/persistence.service.ts index 64061323d..1f80ddd6e 100644 --- a/src/common/persistence/persistence.service.ts +++ b/src/common/persistence/persistence.service.ts @@ -297,6 +297,10 @@ export class PersistenceService { return await this.execute(this.saveMarketplace.name, this.marketplaceRepository.saveMarketplace(entity)); } + async saveMarketplaces(entity: MarketplaceEntity[]): Promise { + return await this.execute(this.saveMarketplaces.name, this.marketplaceRepository.saveMarketplaces(entity)); + } + async updateMarketplace(entity: MarketplaceEntity): Promise { return await this.execute(this.updateMarketplace.name, this.marketplaceRepository.updateMarketplace(entity)); } @@ -309,6 +313,10 @@ export class PersistenceService { return await this.execute(this.getMarketplaceByAddress.name, this.marketplaceRepository.getMarketplaceByAddress(address)); } + async getMarketplacesByAddress(address: string): Promise { + return await this.execute(this.getMarketplaceByAddress.name, this.marketplaceRepository.getMarketplacesByAddress(address)); + } + async getMarketplacesByKeys(marketplaceKeys: string[]): Promise { return await this.execute(this.getMarketplacesByKeys.name, this.marketplaceRepository.getMarketplacesByKeys(marketplaceKeys)); } diff --git a/src/db/marketplaces/marketplaces.repository.ts b/src/db/marketplaces/marketplaces.repository.ts index d11edc9f1..ddf1e28cf 100644 --- a/src/db/marketplaces/marketplaces.repository.ts +++ b/src/db/marketplaces/marketplaces.repository.ts @@ -17,6 +17,10 @@ export class MarketplaceRepository { return this.marketplaceRepository.findOne({ where: { address } }); } + async getMarketplacesByAddress(address: string): Promise { + return this.marketplaceRepository.find({ where: { address } }); + } + async getMarketplacesByKeys(marketplaceKeys: string[]): Promise { return this.marketplaceRepository .createQueryBuilder('marketplaces') @@ -46,6 +50,10 @@ export class MarketplaceRepository { return this.marketplaceRepository.save(entity); } + async saveMarketplaces(entities: MarketplaceEntity[]): Promise { + return this.marketplaceRepository.save(entities); + } + async updateMarketplace(entity: MarketplaceEntity): Promise { const result = await this.marketplaceRepository.update({ key: entity.key }, entity); return result?.affected === 1; diff --git a/src/modules/marketplaces/marketplaces-mutations.resolver.ts b/src/modules/marketplaces/marketplaces-mutations.resolver.ts index 7b9440aac..2fee87ead 100644 --- a/src/modules/marketplaces/marketplaces-mutations.resolver.ts +++ b/src/modules/marketplaces/marketplaces-mutations.resolver.ts @@ -11,6 +11,8 @@ import { GqlAdminAuthGuard } from '../auth/gql-admin.auth-guard'; import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard'; import { UpdateMarketplaceArgs } from './models/UpdateMarketplaceArgs'; import { UpdateMarketplaceRequest } from './models/requests/UpdateMarketplaceRequest'; +import { UpdateMarketplaceStateArgs } from './models/UpdateMarketplaceStateArgs'; +import { MarketplaceState } from './models/MarketplaceType.enum'; @Resolver(() => Marketplace) export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) { @@ -41,4 +43,16 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) { async whitelistMarketplace(@Args('input') input: WhitelistMarketplaceArgs): Promise { return this.marketplaceService.whitelistMarketplace(WhitelistMarketplaceRequest.fromArgs(input)); } + + @Mutation(() => Boolean) + // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) + async disableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { + return this.marketplaceService.updateMarketplaceState(input.marketplaceScAddress, MarketplaceState.Disable); + } + + @Mutation(() => Boolean) + // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) + async enableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { + return this.marketplaceService.updateMarketplaceState(input.marketplaceScAddress, MarketplaceState.Enable); + } } diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 8ff1e86d4..4fb053aca 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -259,6 +259,32 @@ export class MarketplacesService { } } + async updateMarketplaceState(address: string, martekplaceState: MarketplaceState): Promise { + const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); + if (!marketplaces?.length) { + throw new BadRequestError('No marketplace with this address'); + } + try { + marketplaces.forEach((m) => (m.state = martekplaceState)); + const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); + + if (updatedMarketplaces) { + for (let index = 0; index < updatedMarketplaces.length; index++) { + const element = updatedMarketplaces[index]; + this.triggerCacheInvalidation(element.key, null, element.address); + } + } + return updatedMarketplaces ? true : false; + } catch (error) { + this.logger.error('An error has occured while updating marketplace state', { + path: this.updateMarketplaceState.name, + marketplace: address, + exception: error, + }); + return false; + } + } + async updateMarketplace(request: UpdateMarketplaceRequest): Promise { const marketplace = await this.persistenceService.getMarketplaceByKey(request.marketplaceKey); if (!marketplace) { diff --git a/src/modules/marketplaces/models/UpdateMarketplaceStateArgs.ts b/src/modules/marketplaces/models/UpdateMarketplaceStateArgs.ts new file mode 100644 index 000000000..506d0b53c --- /dev/null +++ b/src/modules/marketplaces/models/UpdateMarketplaceStateArgs.ts @@ -0,0 +1,10 @@ +import { Field, InputType } from '@nestjs/graphql'; +import { Matches } from 'class-validator'; +import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; + +@InputType() +export class UpdateMarketplaceStateArgs { + @Field({ description: 'Smart Contract Address' }) + @Matches(RegExp(ADDRESS_RGX), { message: ADDRESS_ERROR }) + marketplaceScAddress: string; +} From d0ff0252a89678456fdb932832313aeed2e37eb9 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 15:09:56 +0200 Subject: [PATCH 10/25] Update marketplace add also the state --- src/modules/marketplaces/marketplaces.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 4fb053aca..78f444388 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -298,6 +298,7 @@ export class MarketplacesService { name: request.marketplaceName ?? marketplace.name, url: request.marketplaceUrl ?? marketplace.url, type: marketplace.type ?? MarketplaceTypeEnum.Internal, + state: marketplace.state, }), ); From 5db106093de42f398918bfbdf74ee1246525c322 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 23 Nov 2023 15:11:43 +0200 Subject: [PATCH 11/25] Clean up function --- .../marketplaces/marketplaces.service.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 78f444388..3dfbdc570 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -259,24 +259,27 @@ export class MarketplacesService { } } - async updateMarketplaceState(address: string, martekplaceState: MarketplaceState): Promise { - const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); - if (!marketplaces?.length) { - throw new BadRequestError('No marketplace with this address'); - } + async updateMarketplaceState(address: string, marketplaceState: MarketplaceState): Promise { try { - marketplaces.forEach((m) => (m.state = martekplaceState)); + const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); + + if (!marketplaces || marketplaces.length === 0) { + throw new BadRequestError('No marketplace with this address'); + } + + marketplaces.forEach((m) => (m.state = marketplaceState)); + const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); if (updatedMarketplaces) { - for (let index = 0; index < updatedMarketplaces.length; index++) { - const element = updatedMarketplaces[index]; - this.triggerCacheInvalidation(element.key, null, element.address); + for (const updatedMarketplace of updatedMarketplaces) { + this.triggerCacheInvalidation(updatedMarketplace.key, null, updatedMarketplace.address); } } - return updatedMarketplaces ? true : false; + + return !!updatedMarketplaces; } catch (error) { - this.logger.error('An error has occured while updating marketplace state', { + this.logger.error('An error has occurred while updating marketplace state', { path: this.updateMarketplaceState.name, marketplace: address, exception: error, From 3580ffedc12c55d84a0c1848ee8e8630ae94bb29 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Dec 2023 13:01:44 +0200 Subject: [PATCH 12/25] Change rabbit queue to redis --- src/common/services/caching/entities/cache.info.ts | 5 +++++ .../rabbitmq/blockchain-events/nft-events.module.ts | 2 -- .../rabbitmq/blockchain-events/rabbitmq.module.ts | 7 +------ .../rabbitmq/disable-marketplace-events.service.ts | 7 ++++--- .../disable-marketplace-publisher.service.ts | 12 ------------ src/modules/rabbitmq/rabbit-config.ts | 1 - 6 files changed, 10 insertions(+), 24 deletions(-) delete mode 100644 src/modules/rabbitmq/disable-marketplace-publisher.service.ts diff --git a/src/common/services/caching/entities/cache.info.ts b/src/common/services/caching/entities/cache.info.ts index e9d029791..96ed2ab52 100644 --- a/src/common/services/caching/entities/cache.info.ts +++ b/src/common/services/caching/entities/cache.info.ts @@ -308,4 +308,9 @@ export class CacheInfo { key: 'account_likes_count', ttl: 5 * Constants.oneSecond(), }; + + static MarketplaceEvents: CacheInfo = { + key: 'marketplace_events', + ttl: 12 * Constants.oneMonth(), + }; } diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index b4d9f9052..44ca983d7 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -45,12 +45,10 @@ import { PluginModule } from 'src/plugins/plugin.module'; import { AnalyticsEventsService } from './analytics-events.service'; import { AnalyticsModule } from 'src/modules/analytics/analytics.module'; import { MintersModuleGraph } from 'src/modules/minters/minters.module'; -import { RabbitMqModule } from './rabbitmq.module'; @Module({ imports: [ CommonModule, - forwardRef(() => RabbitMqModule.register()), CacheEventsPublisherModule, forwardRef(() => AuctionsModuleGraph), forwardRef(() => CampaignsModuleGraph), diff --git a/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts b/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts index a6d295663..ff1defce1 100644 --- a/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts +++ b/src/modules/rabbitmq/blockchain-events/rabbitmq.module.ts @@ -1,9 +1,6 @@ import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; -import { DynamicModule, Module, forwardRef } from '@nestjs/common'; +import { DynamicModule, Module } from '@nestjs/common'; import { NftEventsModule } from './nft-events.module'; -import { RabbitPublisherService } from '../rabbit.publisher'; -import { DisabledMarketplaceEventsService } from '../disable-marketplace-events.service'; -import { MarketplaceDisablePublisherService } from '../disable-marketplace-publisher.service'; @Module({}) export class RabbitMqModule { @@ -31,8 +28,6 @@ export class RabbitMqModule { }, }), ], - providers: [RabbitPublisherService, DisabledMarketplaceEventsService, MarketplaceDisablePublisherService], - exports: [RabbitPublisherService, DisabledMarketplaceEventsService, MarketplaceDisablePublisherService], }; } } diff --git a/src/modules/rabbitmq/disable-marketplace-events.service.ts b/src/modules/rabbitmq/disable-marketplace-events.service.ts index 8ea53112e..1ef1660b3 100644 --- a/src/modules/rabbitmq/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/disable-marketplace-events.service.ts @@ -1,13 +1,14 @@ import { Injectable } from '@nestjs/common'; -import { MarketplaceDisablePublisherService } from './disable-marketplace-publisher.service'; +import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; +import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; @Injectable() export class DisabledMarketplaceEventsService { - constructor(private disabledMarketplacePublisherService: MarketplaceDisablePublisherService) {} + constructor(private redisCacheService: RedisCacheService) {} public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { if (auctionEvents?.length) { - await this.disabledMarketplacePublisherService.publish({ hash: hash, events: auctionEvents }); + await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, { hash: hash, events: auctionEvents }); } } } diff --git a/src/modules/rabbitmq/disable-marketplace-publisher.service.ts b/src/modules/rabbitmq/disable-marketplace-publisher.service.ts deleted file mode 100644 index 1f291da66..000000000 --- a/src/modules/rabbitmq/disable-marketplace-publisher.service.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { rabbitExchanges } from './rabbit-config'; -import { RabbitPublisherService } from './rabbit.publisher'; - -@Injectable() -export class MarketplaceDisablePublisherService { - constructor(private readonly rabbitPublisherService: RabbitPublisherService) {} - - async publish(payload: any) { - await this.rabbitPublisherService.publish(rabbitExchanges.DISABLE_MARKETPLACE_EVENTS, payload); - } -} diff --git a/src/modules/rabbitmq/rabbit-config.ts b/src/modules/rabbitmq/rabbit-config.ts index 0338f7c32..c6a5f890a 100644 --- a/src/modules/rabbitmq/rabbit-config.ts +++ b/src/modules/rabbitmq/rabbit-config.ts @@ -14,7 +14,6 @@ export interface RabbitModuleConfig { export const rabbitExchanges = { CACHE_INVALIDATION: 'nft-cache-invalidation', NFT_LIKE: 'x_portal_gamification_nft_likes_exchange', - DISABLE_MARKETPLACE_EVENTS: 'marketplace', }; export const rabbitQueues = { From 6f715b875023a305d46e0f71d773f1e42b5bf28c Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Dec 2023 16:57:12 +0200 Subject: [PATCH 13/25] Add redis events handle --- .../account-stats/accounts-stats.module.ts | 18 +++---- src/modules/analytics/analytics.module.ts | 6 +-- src/modules/artists/artists.module.ts | 7 ++- src/modules/assets/assets-getter.service.ts | 3 +- .../auctions/nft-marketplace.abi.service.ts | 3 +- .../marketplaces-mutations.resolver.ts | 2 +- .../marketplaces/marketplaces.module.ts | 2 + .../marketplaces/marketplaces.service.ts | 34 ++++++++++++- .../disable-marketplace-events.module.ts | 50 +++++++++++++++++++ .../disable-marketplace-events.service.ts | 25 ++++++++++ .../acceptGlobalOffer-event.handler.ts | 3 +- .../handlers/acceptOffer-event.handler.ts | 3 +- .../handlers/bid-event.handler.ts | 3 +- .../handlers/buy-event.handler.ts | 3 +- .../handlers/endAuction-event.handler.ts | 3 +- .../handlers/sendOffer-event.handler.ts | 3 +- .../handlers/startAuction-event.handler.ts | 3 +- .../handlers/swapUpdate-event.handler.ts | 3 +- .../handlers/updateListing-event.handler.ts | 3 +- .../handlers/updatePrice-event.handler.ts | 3 +- .../handlers/withdrawAuction-event.handler.ts | 3 +- .../handlers/withdrawOffer-event.handler.ts | 3 +- .../blockchain-events/nft-events.consumer.ts | 6 +-- .../blockchain-events/nft-events.module.ts | 9 ++-- .../revert-events.consumer.ts | 2 +- .../disable-marketplace-events.service.ts | 14 ------ 26 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module.ts create mode 100644 src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts delete mode 100644 src/modules/rabbitmq/disable-marketplace-events.service.ts diff --git a/src/modules/account-stats/accounts-stats.module.ts b/src/modules/account-stats/accounts-stats.module.ts index e57322798..dbfcc3223 100644 --- a/src/modules/account-stats/accounts-stats.module.ts +++ b/src/modules/account-stats/accounts-stats.module.ts @@ -3,22 +3,20 @@ import { MxCommunicationModule } from 'src/common'; import { AccountsStatsResolver } from './accounts-stats.resolver'; import { AccountsStatsService } from './accounts-stats.service'; import { AccountsStatsCachingService } from './accounts-stats.caching.service'; -import { MarketplacesService } from '../marketplaces/marketplaces.service'; -import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service'; import { CollectionsModuleGraph } from '../nftCollections/collections.module'; import { OffersModuleGraph } from '../offers/offers.module'; import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; +import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module'; @Module({ - providers: [ - Logger, - AccountsStatsService, - AccountsStatsCachingService, - AccountsStatsResolver, - MarketplacesService, - MarketplacesCachingService, + providers: [Logger, AccountsStatsService, AccountsStatsCachingService, AccountsStatsResolver], + imports: [ + MxCommunicationModule, + forwardRef(() => CollectionsModuleGraph), + forwardRef(() => OffersModuleGraph), + PubSubListenerModule, + MarketplacesModuleGraph, ], - imports: [MxCommunicationModule, forwardRef(() => CollectionsModuleGraph), forwardRef(() => OffersModuleGraph), PubSubListenerModule], exports: [AccountsStatsService], }) export class AccountsStatsModuleGraph {} diff --git a/src/modules/analytics/analytics.module.ts b/src/modules/analytics/analytics.module.ts index 6095a5175..2792a6151 100644 --- a/src/modules/analytics/analytics.module.ts +++ b/src/modules/analytics/analytics.module.ts @@ -1,7 +1,5 @@ import { forwardRef, Module } from '@nestjs/common'; import { MxCommunicationModule } from 'src/common'; -import { MarketplacesService } from '../marketplaces/marketplaces.service'; -import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service'; import { AuctionsModuleGraph } from '../auctions/auctions.module'; import { CommonModule } from 'src/common.module'; import { TrendingCollectionsService } from './trending/trending-collections.service'; @@ -30,11 +28,10 @@ import { HoldersResolver } from './holders.resolver'; import { AccountsProvider } from '../account-stats/loaders/accounts.loader'; import { AccountsRedisHandler } from '../account-stats/loaders/accounts.redis-handler'; import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; +import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module'; @Module({ providers: [ - MarketplacesService, - MarketplacesCachingService, TrendingCollectionsService, ElasticAnalyticsService, BuyEventParser, @@ -66,6 +63,7 @@ import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; CommonModule, forwardRef(() => AuctionsModuleGraph), forwardRef(() => CollectionsModuleGraph), + forwardRef(() => MarketplacesModuleGraph), TimescaleDbModule, ], exports: [TrendingCollectionsService, ElasticAnalyticsService, AnalyticsService, GeneralAnalyticsService, CollectionsAnalyticsService], diff --git a/src/modules/artists/artists.module.ts b/src/modules/artists/artists.module.ts index 0ad0f4f66..26b922692 100644 --- a/src/modules/artists/artists.module.ts +++ b/src/modules/artists/artists.module.ts @@ -1,16 +1,15 @@ import { Module } from '@nestjs/common'; import { MxCommunicationModule } from 'src/common'; import { ArtistsResolver } from './artists.resolver'; -import { MarketplacesService } from '../marketplaces/marketplaces.service'; -import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service'; import { ArtistsService } from './artists.service'; import { CollectionsModuleGraph } from '../nftCollections/collections.module'; import { CommonModule } from 'src/common.module'; import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module'; +import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module'; @Module({ - providers: [ArtistsService, ArtistsResolver, MarketplacesService, MarketplacesCachingService], - imports: [MxCommunicationModule, CollectionsModuleGraph, CommonModule, PubSubListenerModule], + providers: [ArtistsService, ArtistsResolver], + imports: [MxCommunicationModule, CollectionsModuleGraph, CommonModule, PubSubListenerModule, MarketplacesModuleGraph], exports: [ArtistsService], }) export class ArtistsModuleGraph {} diff --git a/src/modules/assets/assets-getter.service.ts b/src/modules/assets/assets-getter.service.ts index 6469b4da4..cd0ad9253 100644 --- a/src/modules/assets/assets-getter.service.ts +++ b/src/modules/assets/assets-getter.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { MxApiService, MxElasticService } from 'src/common'; import '../../utils/extensions'; import { AssetsLikesService } from './assets-likes.service'; @@ -29,6 +29,7 @@ import { ELASTIC_TOKENS_INDEX } from 'src/utils/constants'; export class AssetsGetterService { constructor( private apiService: MxApiService, + @Inject(forwardRef(() => CollectionsGetterService)) private collectionsService: CollectionsGetterService, private featuredCollectionsService: FeaturedService, private elasticService: MxElasticService, diff --git a/src/modules/auctions/nft-marketplace.abi.service.ts b/src/modules/auctions/nft-marketplace.abi.service.ts index 3eb211388..711fc9432 100644 --- a/src/modules/auctions/nft-marketplace.abi.service.ts +++ b/src/modules/auctions/nft-marketplace.abi.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import '../../utils/extensions'; import { AuctionAbi, BuySftActionArgs, ExternalAuctionAbi } from './models'; import BigNumber from 'bignumber.js'; @@ -50,6 +50,7 @@ export class NftMarketplaceAbiService { private readonly offersService: OffersService, private readonly logger: Logger, private readonly redisCacheService: RedisCacheService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) { this.parser = new ResultsParser(); diff --git a/src/modules/marketplaces/marketplaces-mutations.resolver.ts b/src/modules/marketplaces/marketplaces-mutations.resolver.ts index 2fee87ead..7391b7be6 100644 --- a/src/modules/marketplaces/marketplaces-mutations.resolver.ts +++ b/src/modules/marketplaces/marketplaces-mutations.resolver.ts @@ -53,6 +53,6 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) { @Mutation(() => Boolean) // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) async enableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { - return this.marketplaceService.updateMarketplaceState(input.marketplaceScAddress, MarketplaceState.Enable); + return this.marketplaceService.disable(input.marketplaceScAddress, MarketplaceState.Enable); } } diff --git a/src/modules/marketplaces/marketplaces.module.ts b/src/modules/marketplaces/marketplaces.module.ts index 3451f7944..765eb27cc 100644 --- a/src/modules/marketplaces/marketplaces.module.ts +++ b/src/modules/marketplaces/marketplaces.module.ts @@ -26,6 +26,7 @@ import { ReindexAuctionPriceUpdatedHandler } from './marketplaces-reindex-handle import { ReindexGlobalOfferAcceptedHandler } from './marketplaces-reindex-handlers/reindex-global-offer-accepted.handler'; import { ReindexAuctionUpdatedHandler } from './marketplaces-reindex-handlers/reindex-auction-updated.handler'; import { MarketplacesMutationsResolver } from './marketplaces-mutations.resolver'; +import { DisabledMarketplaceEventsModule } from '../rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module'; @Module({ providers: [ @@ -59,6 +60,7 @@ import { MarketplacesMutationsResolver } from './marketplaces-mutations.resolver forwardRef(() => CommonModule), forwardRef(() => AuctionsModuleGraph), forwardRef(() => OffersModuleGraph), + forwardRef(() => DisabledMarketplaceEventsModule), ], exports: [MarketplacesService, MarketplaceEventsIndexingService, MarketplacesReindexService], }) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 3dfbdc570..8096ce496 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import '../../utils/extensions'; import { CollectionType } from '../assets/models/Collection.type'; import { Marketplace } from './models'; @@ -14,6 +14,7 @@ import { UpdateMarketplaceRequest } from './models/requests/UpdateMarketplaceReq import { CacheEventsPublisherService } from '../rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service'; import { ChangedEvent, CacheEventTypeEnum } from '../rabbitmq/cache-invalidation/events/changed.event'; import { mxConfig } from 'src/config'; +import { DisabledMarketplaceEventsService } from '../rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service'; @Injectable() export class MarketplacesService { @@ -21,6 +22,8 @@ export class MarketplacesService { private readonly persistenceService: PersistenceService, private readonly cacheService: MarketplacesCachingService, private readonly cacheEventsPublisher: CacheEventsPublisherService, + @Inject(forwardRef(() => DisabledMarketplaceEventsService)) + private readonly marketplaceService: DisabledMarketplaceEventsService, private readonly logger: Logger, ) {} @@ -288,6 +291,35 @@ export class MarketplacesService { } } + async disable(address: string, marketplaceState: MarketplaceState): Promise { + try { + const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); + const test = await this.marketplaceService.handleAuctionFor(); + if (!marketplaces || marketplaces.length === 0) { + throw new BadRequestError('No marketplace with this address'); + } + + marketplaces.forEach((m) => (m.state = marketplaceState)); + + const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); + + if (updatedMarketplaces) { + for (const updatedMarketplace of updatedMarketplaces) { + this.triggerCacheInvalidation(updatedMarketplace.key, null, updatedMarketplace.address); + } + } + + return !!updatedMarketplaces; + } catch (error) { + this.logger.error('An error has occurred while updating marketplace state', { + path: this.updateMarketplaceState.name, + marketplace: address, + exception: error, + }); + return false; + } + } + async updateMarketplace(request: UpdateMarketplaceRequest): Promise { const marketplace = await this.persistenceService.getMarketplaceByKey(request.marketplaceKey); if (!marketplace) { diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module.ts new file mode 100644 index 000000000..2885a24da --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module.ts @@ -0,0 +1,50 @@ +import { Module, forwardRef } from '@nestjs/common'; +import { DisabledMarketplaceEventsService } from './disable-marketplace-events.service'; +import { MarketplaceEventsService } from '../marketplace-events.service'; +import { AcceptGlobalOfferEventHandler } from '../handlers/acceptGlobalOffer-event.handler'; +import { AcceptOfferEventHandler } from '../handlers/acceptOffer-event.handler'; +import { BidEventHandler } from '../handlers/bid-event.handler'; +import { BuyEventHandler } from '../handlers/buy-event.handler'; +import { EndAuctionEventHandler } from '../handlers/endAuction-event.handler'; +import { SendOfferEventHandler } from '../handlers/sendOffer-event.handler'; +import { StartAuctionEventHandler } from '../handlers/startAuction-event.handler'; +import { SwapUpdateEventHandler } from '../handlers/swapUpdate-event.handler'; +import { UpdateListingEventHandler } from '../handlers/updateListing-event.handler'; +import { UpdatePriceEventHandler } from '../handlers/updatePrice-event.handler'; +import { WithdrawAuctionEventHandler } from '../handlers/withdrawAuction-event.handler'; +import { WithdrawOfferEventHandler } from '../handlers/withdrawOffer-event.handler'; +import { AuctionsModuleGraph } from 'src/modules/auctions/auctions.module'; +import { MarketplacesModuleGraph } from 'src/modules/marketplaces/marketplaces.module'; +import { NotificationsModuleGraph } from 'src/modules/notifications/notifications.module'; +import { OrdersModuleGraph } from 'src/modules/orders/orders.module'; +import { FeedEventsSenderService } from '../feed-events.service'; +import { OffersModuleGraph } from 'src/modules/offers/offers.module'; + +@Module({ + imports: [ + forwardRef(() => AuctionsModuleGraph), + forwardRef(() => OrdersModuleGraph), + forwardRef(() => NotificationsModuleGraph), + forwardRef(() => MarketplacesModuleGraph), + forwardRef(() => OffersModuleGraph), + ], + providers: [ + DisabledMarketplaceEventsService, + MarketplaceEventsService, + BuyEventHandler, + BidEventHandler, + StartAuctionEventHandler, + EndAuctionEventHandler, + WithdrawAuctionEventHandler, + AcceptGlobalOfferEventHandler, + SendOfferEventHandler, + AcceptOfferEventHandler, + WithdrawOfferEventHandler, + UpdatePriceEventHandler, + UpdateListingEventHandler, + SwapUpdateEventHandler, + FeedEventsSenderService, + ], + exports: [DisabledMarketplaceEventsService], +}) +export class DisabledMarketplaceEventsModule {} diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts new file mode 100644 index 000000000..0a4b42a34 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -0,0 +1,25 @@ +import { Inject, Injectable, forwardRef } from '@nestjs/common'; +import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; +import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; +import { MarketplaceEventsService } from '../marketplace-events.service'; +import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; + +@Injectable() +export class DisabledMarketplaceEventsService { + constructor(private redisCacheService: RedisCacheService, private readonly marketplaceEventsService: MarketplaceEventsService) {} + + public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { + if (auctionEvents?.length) { + await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, { hash: hash, events: auctionEvents }); + } + } + + public async handleAuctionFor() { + const auctionEvents = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); + console.log({ auctionEvents: JSON.stringify(auctionEvents) }); + + if (auctionEvents?.length) { + await this.marketplaceEventsService.handleNftAuctionEvents(auctionEvents, 'hash', MarketplaceTypeEnum.Internal); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts index 82dd0d15d..5f77c0013 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; import { AuctionStatusEnum } from 'src/modules/auctions/models'; @@ -13,6 +13,7 @@ export class AcceptGlobalOfferEventHandler { constructor( private auctionsGetterService: AuctionsGetterService, private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts index da88ca41c..140be69b8 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; import { AuctionStatusEnum } from 'src/modules/auctions/models'; @@ -20,6 +20,7 @@ export class AcceptOfferEventHandler { private readonly auctionsGetterService: AuctionsGetterService, private readonly auctionsService: AuctionsSetterService, private readonly offersService: OffersService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private readonly feedEventsSenderService: FeedEventsSenderService, private readonly notificationsService: NotificationsService, diff --git a/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts index 93c1a8fc6..4b3f44979 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { PersistenceService } from 'src/common/persistence/persistence.service'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; import { AuctionStatusEnum } from 'src/modules/auctions/models'; @@ -22,6 +22,7 @@ export class BidEventHandler { private ordersService: OrdersService, private notificationsService: NotificationsService, private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private readonly persistenceService: PersistenceService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts index 514bae7ea..3a3ffc2ab 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { AuctionEntity } from 'src/db/auctions'; import { KroganSwapAuctionEventEnum, ExternalAuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; @@ -20,6 +20,7 @@ export class BuyEventHandler { private auctionsService: AuctionsSetterService, private ordersService: OrdersService, private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts index ee59d8b7f..0f6f66ace 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { AuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; import { AuctionStatusEnum } from 'src/modules/auctions/models'; @@ -19,6 +19,7 @@ export class EndAuctionEventHandler { private auctionsService: AuctionsSetterService, private ordersService: OrdersService, private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private notificationsService: NotificationsService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts index 1fa0c4c1a..827684e31 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { OfferEntity } from 'src/db/offers'; import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; @@ -15,6 +15,7 @@ export class SendOfferEventHandler { private readonly offersService: OffersService, private readonly feedEventsSenderService: FeedEventsSenderService, private readonly notificationsService: NotificationsService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts index 9168ba854..270a9a345 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { mxConfig } from 'src/config'; import { AuctionEntity } from 'src/db/auctions'; import { AssetByIdentifierService } from 'src/modules/assets'; @@ -24,6 +24,7 @@ export class StartAuctionEventHandler { private feedEventsSenderService: FeedEventsSenderService, private assetByIdentifierService: AssetByIdentifierService, private usdPriceService: UsdPriceService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts index 36df7ca18..7e950fa98 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { mxConfig } from 'src/config'; import { AuctionEntity } from 'src/db/auctions'; import { KroganSwapAuctionEventEnum } from 'src/modules/assets/models'; @@ -15,6 +15,7 @@ export class SwapUpdateEventHandler { constructor( private auctionsGetterService: AuctionsGetterService, private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private usdPriceService: UsdPriceService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts index 886f4eab7..e83c773a6 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts @@ -1,5 +1,5 @@ import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { AuctionEntity } from 'src/db/auctions'; import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; @@ -16,6 +16,7 @@ export class UpdateListingEventHandler { constructor( private auctionsGetterService: AuctionsGetterService, private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private usdPriceService: UsdPriceService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts index ec7817fc4..377dd652e 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { mxConfig } from 'src/config'; import { AuctionEntity } from 'src/db/auctions'; import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; @@ -17,6 +17,7 @@ export class UpdatePriceEventHandler { constructor( private auctionsGetterService: AuctionsGetterService, private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, private usdPriceService: UsdPriceService, private nftAbiService: NftMarketplaceAbiService, diff --git a/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts index 6e88081bd..a67b5f5cf 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { AuctionEntity } from 'src/db/auctions'; import { AuctionEventEnum, KroganSwapAuctionEventEnum, ExternalAuctionEventEnum } from 'src/modules/assets/models'; import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; @@ -15,6 +15,7 @@ export class WithdrawAuctionEventHandler { constructor( private auctionsGetterService: AuctionsGetterService, private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts index c01daaebe..da7088582 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger } from '@nestjs/common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; import { NotificationsService } from 'src/modules/notifications/notifications.service'; @@ -12,6 +12,7 @@ export class WithdrawOfferEventHandler { constructor( private readonly offersService: OffersService, private readonly notificationsService: NotificationsService, + @Inject(forwardRef(() => MarketplacesService)) private readonly marketplaceService: MarketplacesService, ) {} diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index a2eb27d15..2869afbf0 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Inject, Injectable, forwardRef } from '@nestjs/common'; import { NftEventEnum } from 'src/modules/assets/models'; import { ApiConfigService } from 'src/modules/common/api-config/api.config.service'; import { MarketplaceEventsIndexingService } from 'src/modules/marketplaces/marketplaces-events-indexing.service'; @@ -10,7 +10,7 @@ import { MinterEventsService } from './minter-events.service'; import { NftEventsService } from './nft-events.service'; import { AnalyticsEventsService } from './analytics-events.service'; import { MintersService } from 'src/modules/minters/minters.service'; -import { DisabledMarketplaceEventsService } from '../disable-marketplace-events.service'; +import { DisabledMarketplaceEventsService } from './disable-marketplace/disable-marketplace-events.service'; @Injectable() export class NftEventsConsumer { @@ -30,7 +30,7 @@ export class NftEventsConsumer { connection: 'default', queueName: process.env.RABBITMQ_QUEUE, exchange: process.env.RABBITMQ_EXCHANGE, - dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE, + // dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE, }) async consumeAuctionEvents(nftAuctionEvents: any) { if (nftAuctionEvents?.events) { diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index 44ca983d7..136816092 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -45,7 +45,8 @@ import { PluginModule } from 'src/plugins/plugin.module'; import { AnalyticsEventsService } from './analytics-events.service'; import { AnalyticsModule } from 'src/modules/analytics/analytics.module'; import { MintersModuleGraph } from 'src/modules/minters/minters.module'; - +import { DisabledMarketplaceEventsService } from './disable-marketplace/disable-marketplace-events.service'; +import { DisabledMarketplaceEventsModule } from './disable-marketplace/disable-marketplace-events.module'; @Module({ imports: [ CommonModule, @@ -59,6 +60,7 @@ import { MintersModuleGraph } from 'src/modules/minters/minters.module'; forwardRef(() => MxCommunicationModule), forwardRef(() => OffersModuleGraph), forwardRef(() => PluginModule), + forwardRef(() => DisabledMarketplaceEventsModule), UsdPriceModuleGraph, NftRarityModuleGraph, ScamModule, @@ -84,7 +86,7 @@ import { MintersModuleGraph } from 'src/modules/minters/minters.module'; MinterEventsService, RevertEventsConsumer, RevertEventsService, - ElasiticUpdatesConsumer, + // ElasiticUpdatesConsumer, ElasticUpdatesEventsService, AssetRarityInfoRedisHandler, VerifyContentService, @@ -97,7 +99,8 @@ import { MintersModuleGraph } from 'src/modules/minters/minters.module'; FeedEventsSenderService, UsdPriceService, AnalyticsEventsService, + // DisabledMarketplaceEventsService, ], - exports: [NftEventsService], + exports: [NftEventsService, NftEventsConsumer], }) export class NftEventsModule {} diff --git a/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts index 965e291a0..f05a33539 100644 --- a/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts @@ -10,7 +10,7 @@ export class RevertEventsConsumer { connection: 'default', queueName: process.env.RABBITMQ_QUEUE_REVERT, exchange: process.env.RABBITMQ_EXCHANGE_REVERT, - dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE_REVERT, + // dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE_REVERT, }) async consumeRevertEvents(nftAuctionEvents: any) { if (nftAuctionEvents.events) { diff --git a/src/modules/rabbitmq/disable-marketplace-events.service.ts b/src/modules/rabbitmq/disable-marketplace-events.service.ts deleted file mode 100644 index 1ef1660b3..000000000 --- a/src/modules/rabbitmq/disable-marketplace-events.service.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; -import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; - -@Injectable() -export class DisabledMarketplaceEventsService { - constructor(private redisCacheService: RedisCacheService) {} - - public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { - if (auctionEvents?.length) { - await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, { hash: hash, events: auctionEvents }); - } - } -} From e55ea80973979344563ba6702507f58e8bedb023 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 11:21:52 +0200 Subject: [PATCH 14/25] update redis queues --- .../disable-marketplace-events.service.ts | 14 +++++++------- .../handlers/startAuction-event.handler.ts | 1 + .../marketplace-events.service.ts | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts index 0a4b42a34..8f77025fd 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, forwardRef } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; import { MarketplaceEventsService } from '../marketplace-events.service'; @@ -10,16 +10,16 @@ export class DisabledMarketplaceEventsService { public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { if (auctionEvents?.length) { - await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, { hash: hash, events: auctionEvents }); + await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, JSON.stringify([{ hash: hash, events: auctionEvents }])); } } public async handleAuctionFor() { - const auctionEvents = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); - console.log({ auctionEvents: JSON.stringify(auctionEvents) }); - - if (auctionEvents?.length) { - await this.marketplaceEventsService.handleNftAuctionEvents(auctionEvents, 'hash', MarketplaceTypeEnum.Internal); + const events = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); + const parseEvents = JSON.parse(events[0]); + const auctionsEvents = parseEvents[0]; + if (auctionsEvents?.events?.length) { + await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, MarketplaceTypeEnum.Internal); } } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts index 270a9a345..6bcfc4556 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts @@ -29,6 +29,7 @@ export class StartAuctionEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { + console.log(11111111); const { auctionTokenEvent, topics } = this.getEventAndTopics(event); if (!auctionTokenEvent && !topics) return; diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index 4b63dde53..eb305e462 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -37,6 +37,7 @@ export class MarketplaceEventsService { public async handleNftAuctionEvents(auctionEvents: any[], hash: string, marketplaceType: MarketplaceTypeEnum) { for (let event of auctionEvents) { + console.log({ event }); switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: From 176dbba2e709fa4aac9d49ed4cff97761b7dc899 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 11:49:30 +0200 Subject: [PATCH 15/25] Update handle events for disable marketplace --- src/modules/marketplaces/marketplaces.service.ts | 2 +- .../disable-marketplace-events.service.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 8096ce496..8f9fdaea6 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -294,11 +294,11 @@ export class MarketplacesService { async disable(address: string, marketplaceState: MarketplaceState): Promise { try { const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); - const test = await this.marketplaceService.handleAuctionFor(); if (!marketplaces || marketplaces.length === 0) { throw new BadRequestError('No marketplace with this address'); } + const test = await this.marketplaceService.handleAuctionFor(marketplaces); marketplaces.forEach((m) => (m.state = marketplaceState)); const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts index 8f77025fd..5a3dc137e 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -3,6 +3,8 @@ import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; import { MarketplaceEventsService } from '../marketplace-events.service'; import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { Marketplace } from 'src/modules/marketplaces/models'; +import { MarketplaceEntity } from 'src/db/marketplaces'; @Injectable() export class DisabledMarketplaceEventsService { @@ -14,12 +16,12 @@ export class DisabledMarketplaceEventsService { } } - public async handleAuctionFor() { + public async handleAuctionFor(marketplaces: MarketplaceEntity[]) { const events = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); const parseEvents = JSON.parse(events[0]); const auctionsEvents = parseEvents[0]; if (auctionsEvents?.events?.length) { - await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, MarketplaceTypeEnum.Internal); + await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, marketplaces[0].type); } } } From 45ea3a8290cf56da94e438fc1ebb3e22ede572b4 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 14:48:14 +0200 Subject: [PATCH 16/25] Add check for events --- .../disable-marketplace-events.service.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts index 5a3dc137e..af2e448f3 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -18,10 +18,12 @@ export class DisabledMarketplaceEventsService { public async handleAuctionFor(marketplaces: MarketplaceEntity[]) { const events = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); - const parseEvents = JSON.parse(events[0]); - const auctionsEvents = parseEvents[0]; - if (auctionsEvents?.events?.length) { - await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, marketplaces[0].type); + if (events?.length) { + const parseEvents = JSON.parse(events[0]); + const auctionsEvents = parseEvents[0]; + if (auctionsEvents?.events?.length) { + await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, marketplaces[0].type); + } } } } From d7630b5a3ee31896e7d391b5eb49c97c3e0d3ffe Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 15:40:08 +0200 Subject: [PATCH 17/25] Fix tests --- .../marketplaces/tests/marketplaces.service.spec.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index 0d5b54dbd..5b7cac092 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -4,7 +4,7 @@ import { CollectionType } from 'src/modules/assets/models'; import { MarketplacesService } from '../marketplaces.service'; import { MarketplacesCachingService } from '../marketplaces-caching.service'; import { MarketplaceCollectionEntity, MarketplaceEntity } from 'src/db/marketplaces'; -import { MarketplaceTypeEnum } from '../models/MarketplaceType.enum'; +import { MarketplaceState, MarketplaceTypeEnum } from '../models/MarketplaceType.enum'; import { MarketplaceFilters } from '../models/Marketplace.Filter'; import { Marketplace } from '../models'; import { RemoveWhitelistCollectionRequest, WhitelistCollectionRequest } from '../models/requests/WhitelistCollectionOnMarketplaceRequest'; @@ -13,6 +13,7 @@ import { Logger } from '@nestjs/common'; import { WhitelistMarketplaceRequest } from '../models/requests/WhitelistMarketplaceRequest'; import { UpdateMarketplaceRequest } from '../models/requests/UpdateMarketplaceRequest'; import { CacheEventsPublisherService } from 'src/modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service'; +import { DisabledMarketplaceEventsService } from 'src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service'; describe('Marketplaces Service', () => { let service: MarketplacesService; @@ -24,12 +25,14 @@ describe('Marketplaces Service', () => { name: 'name', key: 'xoxno', type: MarketplaceTypeEnum.External, + state: MarketplaceState.Enable, }), new MarketplaceEntity({ address: 'address2', name: 'name2', key: 'common', type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, }), ], 2, @@ -49,6 +52,10 @@ describe('Marketplaces Service', () => { provide: MarketplacesCachingService, useFactory: () => ({}), }, + { + provide: DisabledMarketplaceEventsService, + useFactory: () => ({}), + }, { provide: PersistenceService, useFactory: () => ({}), From 5d30c3c85f4937eb6e9cba67e17f170069b6fc8c Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 17:44:40 +0200 Subject: [PATCH 18/25] Add unit tests for new marketplace functions --- .../marketplaces-mutations.resolver.ts | 4 +- .../marketplaces/marketplaces.service.ts | 48 ++++-- .../tests/marketplaces.service.spec.ts | 158 ++++++++++++++---- .../disable-marketplace-events.service.ts | 2 +- 4 files changed, 156 insertions(+), 56 deletions(-) diff --git a/src/modules/marketplaces/marketplaces-mutations.resolver.ts b/src/modules/marketplaces/marketplaces-mutations.resolver.ts index 7391b7be6..d63a8d987 100644 --- a/src/modules/marketplaces/marketplaces-mutations.resolver.ts +++ b/src/modules/marketplaces/marketplaces-mutations.resolver.ts @@ -47,12 +47,12 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) { @Mutation(() => Boolean) // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) async disableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { - return this.marketplaceService.updateMarketplaceState(input.marketplaceScAddress, MarketplaceState.Disable); + return this.marketplaceService.disableMarketplace(input.marketplaceScAddress, MarketplaceState.Disable); } @Mutation(() => Boolean) // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) async enableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { - return this.marketplaceService.disable(input.marketplaceScAddress, MarketplaceState.Enable); + return this.marketplaceService.enableMarketplace(input.marketplaceScAddress, MarketplaceState.Enable); } } diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index 8f9fdaea6..c6fdd8f92 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -262,15 +262,14 @@ export class MarketplacesService { } } - async updateMarketplaceState(address: string, marketplaceState: MarketplaceState): Promise { - try { - const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); - - if (!marketplaces || marketplaces.length === 0) { - throw new BadRequestError('No marketplace with this address'); - } + async disableMarketplace(address: string, marketplaceState: MarketplaceState): Promise { + const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); - marketplaces.forEach((m) => (m.state = marketplaceState)); + if (!marketplaces || marketplaces.length === 0) { + throw new BadRequestError('No marketplace with this address'); + } + try { + marketplaces?.forEach((m) => (m.state = marketplaceState)); const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); @@ -282,7 +281,7 @@ export class MarketplacesService { return !!updatedMarketplaces; } catch (error) { - this.logger.error('An error has occurred while updating marketplace state', { + this.logger.error('An error has occurred while disabaling marketplace state', { path: this.updateMarketplaceState.name, marketplace: address, exception: error, @@ -291,15 +290,14 @@ export class MarketplacesService { } } - async disable(address: string, marketplaceState: MarketplaceState): Promise { + async enableMarketplace(address: string, marketplaceState: MarketplaceState): Promise { + const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); + if (!marketplaces || marketplaces.length === 0) { + throw new BadRequestError('No marketplace with this address'); + } try { - const marketplaces = await this.persistenceService.getMarketplacesByAddress(address); - if (!marketplaces || marketplaces.length === 0) { - throw new BadRequestError('No marketplace with this address'); - } - - const test = await this.marketplaceService.handleAuctionFor(marketplaces); - marketplaces.forEach((m) => (m.state = marketplaceState)); + await this.marketplaceService.processMissedEventsSinceDisabled(marketplaces); + marketplaces?.forEach((m) => (m.state = marketplaceState)); const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); @@ -311,7 +309,7 @@ export class MarketplacesService { return !!updatedMarketplaces; } catch (error) { - this.logger.error('An error has occurred while updating marketplace state', { + this.logger.error('An error has occurred while enabeling marketplace', { path: this.updateMarketplaceState.name, marketplace: address, exception: error, @@ -375,4 +373,18 @@ export class MarketplacesService { }), ); } + + private async updateMarketplaceState(marketplaces: MarketplaceEntity[], marketplaceState: MarketplaceState) { + marketplaces?.forEach((m) => (m.state = marketplaceState)); + + const updatedMarketplaces = await this.persistenceService.saveMarketplaces(marketplaces); + + if (updatedMarketplaces) { + for (const updatedMarketplace of updatedMarketplaces) { + this.triggerCacheInvalidation(updatedMarketplace.key, null, updatedMarketplace.address); + } + } + + return !!updatedMarketplaces; + } } diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index 5b7cac092..790030a8f 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -18,7 +18,7 @@ import { DisabledMarketplaceEventsService } from 'src/modules/rabbitmq/blockchai describe('Marketplaces Service', () => { let service: MarketplacesService; let module: TestingModule; - const [inputMarketplace, inputCount] = [ + const [inputMarketplaces, inputCount] = [ [ new MarketplaceEntity({ address: 'address', @@ -106,7 +106,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -132,7 +132,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -166,7 +166,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -192,7 +192,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -218,7 +218,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -245,7 +245,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -277,7 +277,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -293,7 +293,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -310,7 +310,7 @@ describe('Marketplaces Service', () => { const expectedResult = ['address2']; cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -355,7 +355,7 @@ describe('Marketplaces Service', () => { const expectedResult = ['address']; cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -402,7 +402,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -435,7 +435,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -467,7 +467,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -504,7 +504,7 @@ describe('Marketplaces Service', () => { }); cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -541,7 +541,7 @@ describe('Marketplaces Service', () => { type: MarketplaceTypeEnum.External, }); - persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); cacheService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce( new Marketplace({ address: 'address2', @@ -567,7 +567,7 @@ describe('Marketplaces Service', () => { type: MarketplaceTypeEnum.Internal, }); - persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); cacheService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce( new Marketplace({ @@ -606,7 +606,7 @@ describe('Marketplaces Service', () => { count: 2, }); - persistenceService.getMarketplaces = jest.fn().mockReturnValueOnce([inputMarketplace, inputCount]); + persistenceService.getMarketplaces = jest.fn().mockReturnValueOnce([inputMarketplaces, inputCount]); const result = await service.getMarketplacesFromDb(); @@ -625,7 +625,7 @@ describe('Marketplaces Service', () => { type: MarketplaceTypeEnum.External, }); - persistenceService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce([inputMarketplace[0]]); + persistenceService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce([inputMarketplaces[0]]); const result = await service.getMarketplaceByAddressAndCollectionFromDb('', ''); expect(result).toMatchObject(expectedResult); @@ -653,7 +653,7 @@ describe('Marketplaces Service', () => { type: MarketplaceTypeEnum.External, }); - persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); const result = await service.getMarketplaceByAddress(''); expect(result).toMatchObject(expectedResult); @@ -677,7 +677,7 @@ describe('Marketplaces Service', () => { cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplace, + items: inputMarketplaces, count: inputCount, }), ); @@ -696,7 +696,7 @@ describe('Marketplaces Service', () => { const persistenceService = module.get(PersistenceService); persistenceService.getMarketplaceByKeyAndCollection = jest.fn().mockReturnValueOnce(null); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.saveMarketplaceCollection = jest.fn(() => { throw new Error(); }); @@ -712,12 +712,12 @@ describe('Marketplaces Service', () => { persistenceService.getMarketplaceByKeyAndCollection = jest.fn().mockReturnValueOnce(null); eventPublisher.publish = jest.fn(); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.saveMarketplaceCollection = jest.fn().mockReturnValueOnce( new MarketplaceCollectionEntity({ collectionIdentifier: 'collection', - marketplaces: [inputMarketplace[0]], + marketplaces: [inputMarketplaces[0]], }), ); const expectedResult = await service.whitelistCollectionOnMarketplace(new WhitelistCollectionRequest({ marketplaceKey: 'xoxno' })); @@ -729,14 +729,14 @@ describe('Marketplaces Service', () => { const persistenceService = module.get(PersistenceService); const eventPublisher = module.get(CacheEventsPublisherService); - persistenceService.getMarketplaceByKeyAndCollection = jest.fn().mockReturnValueOnce(inputMarketplace); + persistenceService.getMarketplaceByKeyAndCollection = jest.fn().mockReturnValueOnce(inputMarketplaces); eventPublisher.publish = jest.fn(); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.saveMarketplaceCollection = jest.fn().mockReturnValueOnce( new MarketplaceCollectionEntity({ collectionIdentifier: 'collection', - marketplaces: [inputMarketplace[0]], + marketplaces: [inputMarketplaces[0]], }), ); const expectedResult = await service.whitelistCollectionOnMarketplace(new WhitelistCollectionRequest({ marketplaceKey: 'xoxno' })); @@ -758,7 +758,7 @@ describe('Marketplaces Service', () => { it('when collection not found throws error', async () => { const persistenceService = module.get(PersistenceService); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.getCollectionByKeyAndCollection = jest.fn().mockReturnValueOnce(null); await expect(service.removeWhitelistCollection(new RemoveWhitelistCollectionRequest())).rejects.toThrowError(BadRequestError); @@ -767,7 +767,7 @@ describe('Marketplaces Service', () => { it('when marketplace exists and delete fails returns false', async () => { const persistenceService = module.get(PersistenceService); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.getCollectionByKeyAndCollection = jest.fn().mockReturnValueOnce(new MarketplaceCollectionEntity()); persistenceService.deleteMarketplaceCollection = jest.fn(() => { @@ -786,13 +786,13 @@ describe('Marketplaces Service', () => { const eventPublisher = module.get(CacheEventsPublisherService); eventPublisher.publish = jest.fn(); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.getCollectionByKeyAndCollection = jest.fn().mockReturnValueOnce(new MarketplaceCollectionEntity()); persistenceService.deleteMarketplaceCollection = jest.fn().mockReturnValueOnce( new MarketplaceCollectionEntity({ collectionIdentifier: 'collection', - marketplaces: [inputMarketplace[0]], + marketplaces: [inputMarketplaces[0]], }), ); const expectedResult = await service.removeWhitelistCollection( @@ -807,7 +807,7 @@ describe('Marketplaces Service', () => { it('when marketplace key exists throws error', async () => { const persistenceService = module.get(PersistenceService); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); await expect(service.whitelistMarketplace(new WhitelistMarketplaceRequest())).rejects.toThrowError(BadRequestError); }); @@ -832,7 +832,7 @@ describe('Marketplaces Service', () => { eventPublisher.publish = jest.fn(); persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(null); - persistenceService.saveMarketplace = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.saveMarketplace = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); const expectedResult = await service.whitelistMarketplace(new WhitelistMarketplaceRequest({ marketplaceKey: 'xoxno' })); expect(expectedResult).toBeTruthy(); @@ -851,7 +851,7 @@ describe('Marketplaces Service', () => { it('when marketplace exists and save fails returns false', async () => { const persistenceService = module.get(PersistenceService); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.updateMarketplace = jest.fn(() => { throw new Error(); }); @@ -866,7 +866,7 @@ describe('Marketplaces Service', () => { const eventPublisher = module.get(CacheEventsPublisherService); eventPublisher.publish = jest.fn(); - persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplaces[0]); persistenceService.updateMarketplace = jest.fn().mockReturnValueOnce(true); const expectedResult = await service.updateMarketplace(new UpdateMarketplaceRequest({ marketplaceKey: 'xoxno' })); @@ -903,4 +903,92 @@ describe('Marketplaces Service', () => { expect(result).toMatchObject(expectedResult); }); }); + + describe('disableMarketplace', () => { + it('when marketplace does not exist throws error', async () => { + const persistenceService = module.get(PersistenceService); + + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(null); + + await expect(service.disableMarketplace('address', MarketplaceState.Disable)).rejects.toThrowError(BadRequestError); + }); + + it('when marketplace exists and save fails returns false', async () => { + const persistenceService = module.get(PersistenceService); + + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces); + persistenceService.saveMarketplaces = jest.fn(() => { + throw new Error(); + }); + + const expectedResult = await service.disableMarketplace('address', MarketplaceState.Disable); + + expect(expectedResult).toBeFalsy(); + }); + + it('when marketplace does exists and update is succesfull returns true', async () => { + const persistenceService = module.get(PersistenceService); + const eventPublisher = module.get(CacheEventsPublisherService); + + eventPublisher.publish = jest.fn(); + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces); + + persistenceService.saveMarketplaces = jest.fn().mockReturnValueOnce(inputMarketplaces); + const expectedResult = await service.disableMarketplace('address', MarketplaceState.Disable); + + expect(expectedResult).toBeTruthy(); + }); + }); + + describe('enableMarketplace', () => { + it('when marketplace does not exist throws error', async () => { + const persistenceService = module.get(PersistenceService); + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(null); + + await expect(service.enableMarketplace('address', MarketplaceState.Enable)).rejects.toThrowError(BadRequestError); + }); + + it('when marketplace exists and save fails returns false', async () => { + const persistenceService = module.get(PersistenceService); + const disabledMarketplaceService = module.get(DisabledMarketplaceEventsService); + + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces); + disabledMarketplaceService.processMissedEventsSinceDisabled = jest.fn(() => { + throw new Error(); + }); + + const expectedResult = await service.enableMarketplace('address', MarketplaceState.Enable); + + expect(expectedResult).toBeFalsy(); + }); + + it('when marketplace exists, process succeeds but save fails returns false', async () => { + const persistenceService = module.get(PersistenceService); + const disabledMarketplaceService = module.get(DisabledMarketplaceEventsService); + + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces); + disabledMarketplaceService.processMissedEventsSinceDisabled = jest.fn(); + persistenceService.saveMarketplaces = jest.fn(() => { + throw new Error(); + }); + + const expectedResult = await service.enableMarketplace('address', MarketplaceState.Enable); + + expect(expectedResult).toBeFalsy(); + }); + + it('when marketplace does exists and update is succesfull returns true', async () => { + const persistenceService = module.get(PersistenceService); + const eventPublisher = module.get(CacheEventsPublisherService); + const disabledMarketplaceService = module.get(DisabledMarketplaceEventsService); + + eventPublisher.publish = jest.fn(); + persistenceService.getMarketplacesByAddress = jest.fn().mockReturnValueOnce(inputMarketplaces); + persistenceService.saveMarketplaces = jest.fn().mockReturnValueOnce(inputMarketplaces); + disabledMarketplaceService.processMissedEventsSinceDisabled = jest.fn(); + const expectedResult = await service.disableMarketplace('address', MarketplaceState.Disable); + + expect(expectedResult).toBeTruthy(); + }); + }); }); diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts index af2e448f3..7b3371857 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -16,7 +16,7 @@ export class DisabledMarketplaceEventsService { } } - public async handleAuctionFor(marketplaces: MarketplaceEntity[]) { + public async processMissedEventsSinceDisabled(marketplaces: MarketplaceEntity[]) { const events = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); if (events?.length) { const parseEvents = JSON.parse(events[0]); From 25277d0975ba10501295a7eeffde35153610d4c9 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Dec 2023 18:45:29 +0200 Subject: [PATCH 19/25] Add missing tests --- .../marketplaces/marketplaces.service.ts | 7 +- .../tests/marketplaces.service.spec.ts | 101 ++++++++++++++++-- .../blockchain-events/nft-events.consumer.ts | 2 +- 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index c6fdd8f92..2ee825c5b 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -85,13 +85,14 @@ export class MarketplacesService { return externalMarketplaces.map((m) => m.address); } - async getDisableMarketplacesAddreses(): Promise { + async getDisabledMarketplacesAddreses(): Promise { let allMarketplaces = await this.getAllMarketplaces(); - const externalMarketplaces = allMarketplaces?.items?.filter((m) => m.state === MarketplaceState.Disable); + const disabledMarketplaces = allMarketplaces?.items?.filter((m) => m.state === MarketplaceState.Disable); - return externalMarketplaces.map((m) => m.address); + return disabledMarketplaces.map((m) => m.address); } + async getMarketplacesAddreses(): Promise { let allMarketplaces = await this.getAllMarketplaces(); diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index 790030a8f..e6f0898d1 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -34,8 +34,15 @@ describe('Marketplaces Service', () => { type: MarketplaceTypeEnum.Internal, state: MarketplaceState.Enable, }), + new MarketplaceEntity({ + address: 'disabledAddress', + name: 'name', + key: 'test', + type: MarketplaceTypeEnum.External, + state: MarketplaceState.Disable, + }), ], - 2, + 3, ]; beforeEach(async () => { @@ -92,6 +99,7 @@ describe('Marketplaces Service', () => { address: 'address', name: 'name', key: 'xoxno', + state: MarketplaceState.Enable, type: MarketplaceTypeEnum.External, }), new Marketplace({ @@ -99,9 +107,17 @@ describe('Marketplaces Service', () => { name: 'name2', key: 'common', type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, + }), + new Marketplace({ + address: 'disabledAddress', + name: 'name', + key: 'test', + type: MarketplaceTypeEnum.External, + state: MarketplaceState.Disable, }), ], - count: 2, + count: 3, }); cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( @@ -115,6 +131,7 @@ describe('Marketplaces Service', () => { expect(result).toMatchObject(expectedResult); }); + it('when filters by marketplaceKey and marketplaceAddress returns list with one item', async () => { const cacheService = module.get(MarketplacesCachingService); @@ -398,7 +415,7 @@ describe('Marketplaces Service', () => { describe('getMarketplacesAddreses', () => { it('returns list of addresses for all marketplaces', async () => { const cacheService = module.get(MarketplacesCachingService); - const expectedResult = ['address', 'address2']; + const expectedResult = ['address', 'address2', 'disabledAddress']; cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ @@ -591,19 +608,43 @@ describe('Marketplaces Service', () => { const expectedResult = new CollectionType({ items: [ new Marketplace({ + acceptedPaymentIdentifiers: null, address: 'address', - name: 'name', + iconUrl: 'https://media.elrond.com/markets/xoxno.svg', + id: undefined, key: 'xoxno', + lastIndexTimestamp: undefined, + name: 'name', + state: MarketplaceState.Enable, type: MarketplaceTypeEnum.External, + url: undefined, }), new Marketplace({ + acceptedPaymentIdentifiers: null, address: 'address2', - name: 'name2', + iconUrl: 'https://media.elrond.com/markets/metaspace.svg', + id: undefined, key: 'common', + lastIndexTimestamp: undefined, + name: 'name2', + state: MarketplaceState.Enable, type: MarketplaceTypeEnum.Internal, + url: undefined, + }), + new Marketplace({ + acceptedPaymentIdentifiers: null, + address: 'disabledAddress', + iconUrl: 'https://media.elrond.com/markets/test.svg', + id: undefined, + key: 'test', + lastIndexTimestamp: undefined, + name: 'name', + state: MarketplaceState.Disable, + type: MarketplaceTypeEnum.External, + url: undefined, }), ], - count: 2, + count: 3, }); persistenceService.getMarketplaces = jest.fn().mockReturnValueOnce([inputMarketplaces, inputCount]); @@ -991,4 +1032,52 @@ describe('Marketplaces Service', () => { expect(expectedResult).toBeTruthy(); }); }); + + describe('getDisableMarketplacesAddreses', () => { + it('returns list of addresses of disabled marketplaces', async () => { + const cacheService = module.get(MarketplacesCachingService); + const expectedResult = ['disabledAddress']; + cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( + new CollectionType({ + items: inputMarketplaces, + count: inputCount, + }), + ); + + const result = await service.getDisabledMarketplacesAddreses(); + + expect(result).toMatchObject(expectedResult); + }); + + it('when no expernal marketplace exists returns empty array', async () => { + const cacheService = module.get(MarketplacesCachingService); + + const expectedResult = []; + cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( + new CollectionType({ + items: [ + new Marketplace({ + address: 'address', + name: 'name', + key: 'xoxno', + type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, + }), + new Marketplace({ + address: 'address2', + name: 'name2', + key: 'common', + type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, + }), + ], + count: 2, + }), + ); + + const result = await service.getDisabledMarketplacesAddreses(); + + expect(result).toMatchObject(expectedResult); + }); + }); }); diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index 2869afbf0..f19b684ef 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -36,7 +36,7 @@ export class NftEventsConsumer { if (nftAuctionEvents?.events) { const internalMarketplaces = await this.marketplaceService.getInternalMarketplacesAddreses(); const externalMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); - const disabledMarketplaces = await this.marketplaceService.getDisableMarketplacesAddreses(); + const disabledMarketplaces = await this.marketplaceService.getDisabledMarketplacesAddreses(); console.log({ disabledMarketplaces: JSON.stringify(disabledMarketplaces) }); const disabledMarketplacesEvents = nftAuctionEvents?.events?.filter( From 3f397d86db09de4af584a54e7e32e31576054f07 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 6 Dec 2023 10:27:08 +0200 Subject: [PATCH 20/25] delete console logs --- .../blockchain-events/handlers/startAuction-event.handler.ts | 1 - .../rabbitmq/blockchain-events/marketplace-events.service.ts | 1 - src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts index 6bcfc4556..270a9a345 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts @@ -29,7 +29,6 @@ export class StartAuctionEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - console.log(11111111); const { auctionTokenEvent, topics } = this.getEventAndTopics(event); if (!auctionTokenEvent && !topics) return; diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index eb305e462..4b63dde53 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -37,7 +37,6 @@ export class MarketplaceEventsService { public async handleNftAuctionEvents(auctionEvents: any[], hash: string, marketplaceType: MarketplaceTypeEnum) { for (let event of auctionEvents) { - console.log({ event }); switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index f19b684ef..e598bda6e 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -38,11 +38,9 @@ export class NftEventsConsumer { const externalMarketplaces = await this.marketplaceService.getExternalMarketplacesAddreses(); const disabledMarketplaces = await this.marketplaceService.getDisabledMarketplacesAddreses(); - console.log({ disabledMarketplaces: JSON.stringify(disabledMarketplaces) }); const disabledMarketplacesEvents = nftAuctionEvents?.events?.filter( (e: { address: any }) => disabledMarketplaces.includes(e.address) === true, ); - console.log({ disabledMarketplacesEvents: JSON.stringify(disabledMarketplacesEvents) }); const internalMarketplaceEvents = nftAuctionEvents?.events?.filter( (e: { address: any }) => internalMarketplaces.includes(e.address) === true, From 3570d6e38a2d642257ee96ae6954ef39f23aaa88 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 6 Dec 2023 10:46:37 +0200 Subject: [PATCH 21/25] remove commented code --- src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts | 2 +- .../rabbitmq/blockchain-events/revert-events.consumer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index e598bda6e..0c086afb5 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -30,7 +30,7 @@ export class NftEventsConsumer { connection: 'default', queueName: process.env.RABBITMQ_QUEUE, exchange: process.env.RABBITMQ_EXCHANGE, - // dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE, + dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE, }) async consumeAuctionEvents(nftAuctionEvents: any) { if (nftAuctionEvents?.events) { diff --git a/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts index f05a33539..965e291a0 100644 --- a/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/revert-events.consumer.ts @@ -10,7 +10,7 @@ export class RevertEventsConsumer { connection: 'default', queueName: process.env.RABBITMQ_QUEUE_REVERT, exchange: process.env.RABBITMQ_EXCHANGE_REVERT, - // dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE_REVERT, + dlqExchange: process.env.RABBITMQ_DLQ_EXCHANGE_REVERT, }) async consumeRevertEvents(nftAuctionEvents: any) { if (nftAuctionEvents.events) { From 796ee7dcafb01aeb18341a572bc228e0742b7b32 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 6 Dec 2023 12:10:25 +0200 Subject: [PATCH 22/25] Remove custom filters on asset --- src/modules/assets/assets-getter.service.ts | 26 ++++++++++----------- src/modules/common/filters/filtersTypes.ts | 4 ---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/modules/assets/assets-getter.service.ts b/src/modules/assets/assets-getter.service.ts index cd0ad9253..9c2fc36db 100644 --- a/src/modules/assets/assets-getter.service.ts +++ b/src/modules/assets/assets-getter.service.ts @@ -66,19 +66,19 @@ export class AssetsGetterService { : this.getApiQuery(filters, offset, limit); const apiCountQuery = this.getApiQueryForCount(filters); - if (filters.ownerAddress && filters.customFilters) { - const [ticketsCollections] = await this.featuredCollectionsService.getFeaturedCollections( - new FeaturedCollectionsFilter({ type: FeaturedCollectionTypeEnum.Tickets }), - ); - if (!ticketsCollections || ticketsCollections?.length === 0) return new CollectionType(); - - const ticketCollectionIdentifiers = ticketsCollections.map((x) => x.collection).toString(); - return await this.getAssetsForUser( - filters.ownerAddress, - `?identifiers=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`, - `?identifiers=${ticketCollectionIdentifiers}`, - ); - } + // if (filters.ownerAddress && filters.customFilters) { + // const [ticketsCollections] = await this.featuredCollectionsService.getFeaturedCollections( + // new FeaturedCollectionsFilter({ type: FeaturedCollectionTypeEnum.Tickets }), + // ); + // if (!ticketsCollections || ticketsCollections?.length === 0) return new CollectionType(); + + // const ticketCollectionIdentifiers = ticketsCollections.map((x) => x.collection).toString(); + // return await this.getAssetsForUser( + // filters.ownerAddress, + // `?identifiers=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`, + // `?identifiers=${ticketCollectionIdentifiers}`, + // ); + // } if (sorting === AssetsSortingEnum.MostLikes) { const assets = await this.assetsLikedService.getMostLikedAssets(); diff --git a/src/modules/common/filters/filtersTypes.ts b/src/modules/common/filters/filtersTypes.ts index 745cc1ef3..1ba4428a7 100644 --- a/src/modules/common/filters/filtersTypes.ts +++ b/src/modules/common/filters/filtersTypes.ts @@ -178,10 +178,6 @@ export class AssetsFilter { @Field(() => NftTypeEnum, { nullable: true }) type: NftTypeEnum; - @IsOptional() - @Field(() => CustomFiltersEnum, { nullable: true }) - customFilters: CustomFiltersEnum; - @Field(() => [NftTrait], { nullable: 'itemsAndList' }) traits: NftTrait[]; From b2c5cff7d57b6e9c4053b88db219605aee0606dc Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 11 Dec 2023 14:00:03 +0200 Subject: [PATCH 23/25] Fix test --- src/modules/marketplaces/tests/marketplaces.service.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index e6f0898d1..c0bcd6027 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -1036,7 +1036,7 @@ describe('Marketplaces Service', () => { describe('getDisableMarketplacesAddreses', () => { it('returns list of addresses of disabled marketplaces', async () => { const cacheService = module.get(MarketplacesCachingService); - const expectedResult = ['disabledAddress']; + const expected = ['disabledAddress']; cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ items: inputMarketplaces, @@ -1046,7 +1046,7 @@ describe('Marketplaces Service', () => { const result = await service.getDisabledMarketplacesAddreses(); - expect(result).toMatchObject(expectedResult); + expect(result).toMatchObject(expected); }); it('when no expernal marketplace exists returns empty array', async () => { From 0121d19698aeaf49a14d9e4c56695e2edc8ae9ea Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 11 Dec 2023 14:33:28 +0200 Subject: [PATCH 24/25] Fix tests --- .../tests/marketplaces.service.spec.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index c0bcd6027..49552905e 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -1039,8 +1039,23 @@ describe('Marketplaces Service', () => { const expected = ['disabledAddress']; cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( new CollectionType({ - items: inputMarketplaces, - count: inputCount, + items: [ + new MarketplaceEntity({ + address: 'address2', + name: 'name2', + key: 'common', + type: MarketplaceTypeEnum.Internal, + state: MarketplaceState.Enable, + }), + new MarketplaceEntity({ + address: 'disabledAddress', + name: 'name', + key: 'test', + type: MarketplaceTypeEnum.External, + state: MarketplaceState.Disable, + }), + ], + count: 2, }), ); From 98fd42a4c5562bbed714c34e4db8448a94793258 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 11 Dec 2023 21:35:45 +0200 Subject: [PATCH 25/25] Code review follow up --- src/modules/assets/assets-getter.service.ts | 18 ------------------ src/modules/assets/models/NftTypes.enum.ts | 8 -------- src/modules/common/filters/filtersTypes.ts | 2 +- .../marketplaces-mutations.resolver.ts | 4 ++-- .../disable-marketplace-events.service.ts | 6 +++--- .../blockchain-events/nft-events.consumer.ts | 2 +- .../blockchain-events/nft-events.module.ts | 3 +-- 7 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/modules/assets/assets-getter.service.ts b/src/modules/assets/assets-getter.service.ts index 9c2fc36db..9e5768ab0 100644 --- a/src/modules/assets/assets-getter.service.ts +++ b/src/modules/assets/assets-getter.service.ts @@ -19,9 +19,6 @@ import { ElasticQuery, ElasticSortOrder, QueryConditionOptions, QueryOperator, Q import { Constants } from '@multiversx/sdk-nestjs-common'; import { RedisCacheService } from '@multiversx/sdk-nestjs-cache'; import { QueryPagination } from 'src/common/services/mx-communication/models/query-pagination'; -import { FeaturedService } from '../featured/featured.service'; -import { FeaturedCollectionsFilter } from '../featured/Featured-Collections.Filter'; -import { FeaturedCollectionTypeEnum } from '../featured/FeatureCollectionType.enum'; import { constants } from 'src/config'; import { ELASTIC_TOKENS_INDEX } from 'src/utils/constants'; @@ -31,7 +28,6 @@ export class AssetsGetterService { private apiService: MxApiService, @Inject(forwardRef(() => CollectionsGetterService)) private collectionsService: CollectionsGetterService, - private featuredCollectionsService: FeaturedService, private elasticService: MxElasticService, private assetByIdentifierService: AssetByIdentifierService, private assetScamLoader: AssetScamInfoProvider, @@ -66,20 +62,6 @@ export class AssetsGetterService { : this.getApiQuery(filters, offset, limit); const apiCountQuery = this.getApiQueryForCount(filters); - // if (filters.ownerAddress && filters.customFilters) { - // const [ticketsCollections] = await this.featuredCollectionsService.getFeaturedCollections( - // new FeaturedCollectionsFilter({ type: FeaturedCollectionTypeEnum.Tickets }), - // ); - // if (!ticketsCollections || ticketsCollections?.length === 0) return new CollectionType(); - - // const ticketCollectionIdentifiers = ticketsCollections.map((x) => x.collection).toString(); - // return await this.getAssetsForUser( - // filters.ownerAddress, - // `?identifiers=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`, - // `?identifiers=${ticketCollectionIdentifiers}`, - // ); - // } - if (sorting === AssetsSortingEnum.MostLikes) { const assets = await this.assetsLikedService.getMostLikedAssets(); return new CollectionType({ diff --git a/src/modules/assets/models/NftTypes.enum.ts b/src/modules/assets/models/NftTypes.enum.ts index 30b25da7f..35397412c 100644 --- a/src/modules/assets/models/NftTypes.enum.ts +++ b/src/modules/assets/models/NftTypes.enum.ts @@ -18,11 +18,3 @@ export enum ScamInfoTypeEnum { registerEnumType(ScamInfoTypeEnum, { name: 'ScamInfoTypeEnum', }); - -export enum CustomFiltersEnum { - Tickets = 'Tickets', -} - -registerEnumType(CustomFiltersEnum, { - name: 'CustomFiltersEnum', -}); diff --git a/src/modules/common/filters/filtersTypes.ts b/src/modules/common/filters/filtersTypes.ts index 1ba4428a7..33357809b 100644 --- a/src/modules/common/filters/filtersTypes.ts +++ b/src/modules/common/filters/filtersTypes.ts @@ -9,7 +9,7 @@ import { NFT_IDENTIFIER_ERROR, NFT_IDENTIFIER_RGX, } from 'src/utils/constants'; -import { CustomFiltersEnum, NftTypeEnum } from '../../assets/models/NftTypes.enum'; +import { NftTypeEnum } from '../../assets/models/NftTypes.enum'; export enum Operator { AND, diff --git a/src/modules/marketplaces/marketplaces-mutations.resolver.ts b/src/modules/marketplaces/marketplaces-mutations.resolver.ts index d63a8d987..689dfaf3a 100644 --- a/src/modules/marketplaces/marketplaces-mutations.resolver.ts +++ b/src/modules/marketplaces/marketplaces-mutations.resolver.ts @@ -45,13 +45,13 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) { } @Mutation(() => Boolean) - // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) + @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) async disableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { return this.marketplaceService.disableMarketplace(input.marketplaceScAddress, MarketplaceState.Disable); } @Mutation(() => Boolean) - // @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) + @UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard) async enableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise { return this.marketplaceService.enableMarketplace(input.marketplaceScAddress, MarketplaceState.Enable); } diff --git a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts index 7b3371857..73aa7abd5 100644 --- a/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.service.ts @@ -11,17 +11,17 @@ export class DisabledMarketplaceEventsService { constructor(private redisCacheService: RedisCacheService, private readonly marketplaceEventsService: MarketplaceEventsService) {} public async handleAuctionEventsForDisableMarketplace(auctionEvents: any[], hash: string) { - if (auctionEvents?.length) { + if (auctionEvents?.length > 0) { await this.redisCacheService.rpush(CacheInfo.MarketplaceEvents.key, JSON.stringify([{ hash: hash, events: auctionEvents }])); } } public async processMissedEventsSinceDisabled(marketplaces: MarketplaceEntity[]) { const events = await this.redisCacheService.lpop(CacheInfo.MarketplaceEvents.key); - if (events?.length) { + if (events?.length > 0) { const parseEvents = JSON.parse(events[0]); const auctionsEvents = parseEvents[0]; - if (auctionsEvents?.events?.length) { + if (auctionsEvents?.events?.length > 0) { await this.marketplaceEventsService.handleNftAuctionEvents(auctionsEvents?.events, auctionsEvents.hash, marketplaces[0].type); } } diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts index 0c086afb5..a8fae1a72 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.consumer.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, forwardRef } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { NftEventEnum } from 'src/modules/assets/models'; import { ApiConfigService } from 'src/modules/common/api-config/api.config.service'; import { MarketplaceEventsIndexingService } from 'src/modules/marketplaces/marketplaces-events-indexing.service'; diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index 136816092..e9f4d5f50 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -86,7 +86,7 @@ import { DisabledMarketplaceEventsModule } from './disable-marketplace/disable-m MinterEventsService, RevertEventsConsumer, RevertEventsService, - // ElasiticUpdatesConsumer, + ElasiticUpdatesConsumer, ElasticUpdatesEventsService, AssetRarityInfoRedisHandler, VerifyContentService, @@ -99,7 +99,6 @@ import { DisabledMarketplaceEventsModule } from './disable-marketplace/disable-m FeedEventsSenderService, UsdPriceService, AnalyticsEventsService, - // DisabledMarketplaceEventsService, ], exports: [NftEventsService, NftEventsConsumer], })