Skip to content

Commit

Permalink
Add plugins module
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Mar 20, 2023
1 parent d98b2a3 commit ffa86b2
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,4 @@ build.yaml

# PEM file(s)
*.pem
/src/plugins
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
"init": "run-script-os",
"init:nix": "rimraf src/plugins && mkdir src/plugins && cp src/plugins.template/plugin.module.ts.template src/plugins/plugin.module.ts",
"prebuild": "rimraf dist",
"build": "nest build && npm run copy-pem",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ type ScamInfo {
}

enum ScamInfoTypeEnum {
none
potentialScam
scam
}
Expand Down
7 changes: 7 additions & 0 deletions src/common/pluggins/plugin.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Asset } from 'src/modules/assets/models/Asset.dto';

@Injectable()
export class PluginService {
async computeScamInfo(_nft: Asset[]): Promise<void> {}
}
19 changes: 19 additions & 0 deletions src/common/services/mx-communication/models/account.info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ScamInfo } from 'src/modules/assets/models/ScamInfo.dto';

export class AccountInfo {
address: string = '';
nonce: number = 0;
balance: string = '';
username: string = '';
code: string = '';
codeHash: string | undefined;
rootHash: string = '';
codeMetadata: string = '';
developerReward: string = '';
ownerAddress: string = '';
scamInfo: ScamInfo | undefined = undefined;

constructor(init?: Partial<AccountInfo>) {
Object.assign(this, init);
}
}
1 change: 1 addition & 0 deletions src/common/services/mx-communication/models/nft.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Nft {
nonce: number;
royalties: string;
timestamp: number;
url: string;
uris: string[];
tags: string[];
metadata: NftMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MxProxyService } from './mx-proxy.service';
import { MxStatsService } from './mx-stats.service';
import { SlackReportService } from './slack-report.service';
import { ConfigService } from '@nestjs/config';
import { MxExtrasApiService } from './mx-extras-api.service';
import { ApiConfigService } from 'src/modules/common/api-config/api.config.service';

@Module({
Expand All @@ -27,7 +26,6 @@ import { ApiConfigService } from 'src/modules/common/api-config/api.config.servi
MxIdentityService,
MxToolsService,
MxFeedService,
MxExtrasApiService,
SlackReportService,
],
exports: [
Expand All @@ -40,7 +38,6 @@ import { ApiConfigService } from 'src/modules/common/api-config/api.config.servi
MxIdentityService,
MxToolsService,
MxFeedService,
MxExtrasApiService,
SlackReportService,
],
})
Expand Down
90 changes: 0 additions & 90 deletions src/common/services/mx-communication/mx-extras-api.service.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/document-db/document-db.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PerformanceProfiler } from '@multiversx/sdk-nestjs';
import { Injectable } from '@nestjs/common';
import { Nft } from 'src/common';
import { ScamInfo } from 'src/modules/assets/models/ScamInfo.dto';
import { MetricsCollector } from 'src/modules/metrics/metrics.collector';
import { NftScamInfoModel } from 'src/modules/scam/models/nft-scam-info.model';
import { CollectionTraitSummary } from 'src/modules/nft-traits/models/collection-traits.model';
import { NftScamInfoRepositoryService } from './repositories/nft-scam.repository';
import { TraitRepositoryService } from './repositories/traits.repository';
import { Asset } from 'src/modules/assets/models';

@Injectable()
export class DocumentDbService {
Expand Down Expand Up @@ -73,7 +73,7 @@ export class DocumentDbService {
}

async saveOrUpdateBulkNftScamInfo(
nfts: Nft[],
nfts: Asset[],
version: string,
): Promise<void> {
return await this.execute(
Expand Down
6 changes: 3 additions & 3 deletions src/document-db/repositories/nft-scam.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
NftScamInfoModel,
NftScamInfoDocument,
} from 'src/modules/scam/models/nft-scam-info.model';
import { Nft } from 'src/common';
import { ScamInfo } from 'src/modules/assets/models/ScamInfo.dto';
import { Asset } from 'src/modules/assets/models';

@Injectable()
export class NftScamInfoRepositoryService extends EntityRepository<NftScamInfoDocument> {
Expand Down Expand Up @@ -42,7 +42,7 @@ export class NftScamInfoRepositoryService extends EntityRepository<NftScamInfoDo
}

async saveOrUpdateBulkNftScamInfo(
nfts: Nft[],
nfts: Asset[],
version: string,
): Promise<void> {
if (!nfts || nfts.length === 0) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class NftScamInfoRepositoryService extends EntityRepository<NftScamInfoDo
}

private async saveOrUpdateBulk(
nfts: Nft[],
nfts: Asset[],
scamEngineVersion: string,
): Promise<void> {
const updates: any = nfts.map((nft) => {
Expand Down
1 change: 1 addition & 0 deletions src/modules/assets/models/NftTypes.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ registerEnumType(NftTypeEnum, {
});

export enum ScamInfoTypeEnum {
none = 'none',
potentialScam = 'potentialScam',
scam = 'scam',
}
Expand Down
17 changes: 13 additions & 4 deletions src/modules/assets/models/ScamInfo.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ObjectType, Field } from '@nestjs/graphql';
import { Nft } from 'src/common';
import { ScamInfoApi } from 'src/common/services/mx-communication/models/scam-info.dto';
import { elasticDictionary } from 'src/config';
import { NftScamInfoModel } from 'src/modules/scam/models/nft-scam-info.model';
import { ScamInfoTypeEnum } from '.';
import { Asset, ScamInfoTypeEnum } from '.';
@ObjectType()
export class ScamInfo {
@Field(() => ScamInfoTypeEnum, { nullable: true })
Expand All @@ -25,7 +24,7 @@ export class ScamInfo {
}

static areApiAndElasticScamInfoDifferent(
nftFromApi: Nft,
nftFromApi: Asset,
nftFromElastic: any,
): boolean {
return (
Expand All @@ -37,7 +36,7 @@ export class ScamInfo {
}

static areApiAndDbScamInfoDifferent(
nftFromApi: Nft,
nftFromApi: Asset,
nftFromDb: NftScamInfoModel,
version: string,
): boolean {
Expand All @@ -59,4 +58,14 @@ export class ScamInfo {
(!nftFromDb.type && nftFromElastic?.[elasticDictionary.scamInfo.typeKey])
);
}

static isScam(scamInfo: ScamInfo): boolean {
return scamInfo.type !== ScamInfoTypeEnum.none;
}

static none(): ScamInfo {
return new ScamInfo({
type: ScamInfoTypeEnum.none,
});
}
}
3 changes: 2 additions & 1 deletion src/modules/rabbitmq/blockchain-events/nft-events.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RevertEventsService } from './revert.events.service';
import { MxCommunicationModule } from 'src/common';
import { MinterEventsService } from './minter-events.service';
import { CommonModule } from 'src/common.module';
import { CacheModule } from 'src/common/services/caching/caching.module';
import { RarityUpdaterService } from 'src/crons/elastic.updater/rarity.updater.service';
import { NsfwUpdaterService } from 'src/crons/elastic.updater/nsfw.updater.service';
import { FlagNftService } from 'src/modules/admins/flag-nft.service';
Expand Down Expand Up @@ -42,6 +41,7 @@ import { OffersModuleGraph } from 'src/modules/offers/offers.module';
import { AcceptOfferEventHandler } from './handlers/acceptOffer-event.handler';
import { WithdrawOfferEventHandler } from './handlers/withdrawOffer-event.handler';
import { UpdateListingEventHandler } from './handlers/updateListing-event.handler';
import { PluginModule } from 'src/plugins/plugin.module';

@Module({
imports: [
Expand All @@ -54,6 +54,7 @@ import { UpdateListingEventHandler } from './handlers/updateListing-event.handle
forwardRef(() => MarketplacesModuleGraph),
forwardRef(() => MxCommunicationModule),
forwardRef(() => OffersModuleGraph),
forwardRef(() => PluginModule),
UsdPriceModuleGraph,
NftRarityModuleGraph,
ScamModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class ElasticUpdatesEventsService {
): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 5000));

let nftsToUpdate: string[] = [];
let nftsToUpdate: Asset[] = [];
let nftsToDelete: string[] = [];
let collectionTypes: { [key: string]: string } = {};

Expand Down Expand Up @@ -174,7 +174,7 @@ export class ElasticUpdatesEventsService {
}

collectionTypes[collection] = nft.type;
nftsToUpdate.push(identifier);
nftsToUpdate.push(nft);
}

nftsToUpdate = [...new Set(nftsToUpdate)];
Expand All @@ -183,10 +183,11 @@ export class ElasticUpdatesEventsService {
return this.documentDbService.deleteNftScamInfo(n);
});

nftsToUpdate.map(
async (collection) =>
await this.nftScamInfoService.validateOrUpdateNftScamInfo(collection),
);
await this.nftScamInfoService.validateOrUpdateNftsScamInfo(nftsToUpdate);
// nftsToUpdate.map(
// async (collection) =>
// await this.nftScamInfoService.validateOrUpdateNftScamInfo(collection),
// );

await Promise.all(deletes);
}
Expand Down
3 changes: 0 additions & 3 deletions src/modules/scam/collection-scam.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Injectable } from '@nestjs/common';
import { MxApiService } from 'src/common';
import { MxExtrasApiService } from 'src/common/services/mx-communication/mx-extras-api.service';
import { CacheEventsPublisherService } from '../rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service';
import {
CacheEventTypeEnum,
Expand All @@ -10,7 +8,6 @@ import {
@Injectable()
export class CollectionScamService {
constructor(
private mxExtrasApiService: MxExtrasApiService,
private readonly cacheEventsPublisher: CacheEventsPublisherService,
) {}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/scam/nft-scam.elastic.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, Logger } from '@nestjs/common';
import { MxElasticService, Nft } from 'src/common';
import { elasticDictionary } from 'src/config';
import { ScamInfoTypeEnum } from '../assets/models';
import { Asset, ScamInfoTypeEnum } from '../assets/models';
import { NftScamInfoModel } from './models/nft-scam-info.model';
import {
getAllCollectionsFromElasticQuery,
Expand Down Expand Up @@ -40,7 +40,7 @@ export class NftScamElasticService {
}

async setBulkNftScamInfoInElastic(
nfts: Nft[],
nfts: Asset[],
clearScamInfoIfEmpty?: boolean,
): Promise<void> {
if (nfts.length > 0) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export class NftScamElasticService {
return collections;
}

buildNftScamInfoBulkUpdate(nfts: Nft[], clearScamInfo?: boolean): string[] {
buildNftScamInfoBulkUpdate(nfts: Asset[], clearScamInfo?: boolean): string[] {
let updates: string[] = [];
for (const nft of nfts) {
if (nft.scamInfo) {
Expand Down
Loading

0 comments on commit ffa86b2

Please sign in to comment.