Skip to content

Commit

Permalink
feat/sovereign (#1341)
Browse files Browse the repository at this point in the history
* add cacheDuration

* add support for NftSubType

* Update elastic.indexer.helper.ts

* Update nft.filter.ts

* Update nft.controller.ts

* add filter.type on collection elastic

* add subType even for SFT

* fix mex.token.charts.spec.ts

* Update nft.controller.ts

* revert changes

* add subType filter

* add collections subType filter

* add address collection roles subType

* add subType filter for roles/collections count

* add accounts/nfts subType filter

* add accounts/collection subType Filter

* improved support for subType filtering

* commented out field decoration for inner transactions in context of graphgql

* fix array subType filter

* Update elastic.indexer.helper.ts

* remove empty line

---------

Co-authored-by: tanghel <tanghel@live.com>
  • Loading branch information
cfaur09 and tanghel authored Oct 22, 2024
1 parent 64040d5 commit 595359b
Show file tree
Hide file tree
Showing 21 changed files with 204 additions and 52 deletions.
1 change: 1 addition & 0 deletions config/config.devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ caching:
cacheTtl: 6
processTtl: 600
poolLimit: 50
cacheDuration: 3
keepAliveTimeout:
downstream: 61000
upstream: 60000
Expand Down
1 change: 1 addition & 0 deletions config/config.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ caching:
cacheTtl: 6
processTtl: 600
poolLimit: 50
cacheDuration: 3
keepAliveTimeout:
downstream: 61000
upstream: 60000
Expand Down
1 change: 1 addition & 0 deletions config/config.testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ caching:
cacheTtl: 6
processTtl: 600
poolLimit: 50
cacheDuration: 3
keepAliveTimeout:
downstream: 61000
upstream: 60000
Expand Down
3 changes: 3 additions & 0 deletions src/common/api-config/api.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,7 @@ export class ApiConfigService {
return serviceUrl;
}

getCacheDuration(): number {
return this.configService.get<number>('caching.cacheDuration') ?? 3;
}
}
30 changes: 27 additions & 3 deletions src/common/indexer/elastic/elastic.indexer.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ElasticIndexerHelper {
elasticQuery = this.getRoleCondition(elasticQuery, 'ESDTTransferRole', address, filter.canTransferRole);
}

if (filter.excludeMetaESDT === true) {
if (filter.excludeMetaESDT === true && !filter.type) {
elasticQuery = elasticQuery.withMustMultiShouldCondition([
...this.nonFungibleEsdtTypes,
...this.semiFungibleEsdtTypes,
Expand All @@ -151,6 +151,10 @@ export class ElasticIndexerHelper {
elasticQuery = elasticQuery.withMustMultiShouldCondition(types, type => QueryType.Match('type', type));
}

if (filter.subType) {
elasticQuery = elasticQuery.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType));
}

return elasticQuery.withMustMatchCondition('token', filter.collection, QueryOperator.AND)
.withMustMultiShouldCondition(filter.identifiers, identifier => QueryType.Match('token', identifier, QueryOperator.AND))
.withSearchWildcardCondition(filter.search, ['token', 'name']);
Expand All @@ -175,12 +179,32 @@ export class ElasticIndexerHelper {
elasticQuery = elasticQuery.withSearchWildcardCondition(filter.search, ['token', 'name']);
}

if (filter.type !== undefined) {
const types = (filter.type ?? '').split(',');
if (filter.type) {
const types = [];

for (const type of filter.type) {
switch (type) {
case NftType.NonFungibleESDT:
types.push(...this.nonFungibleEsdtTypes);
break;
case NftType.SemiFungibleESDT:
types.push(...this.semiFungibleEsdtTypes);
break;
case NftType.MetaESDT:
types.push(...this.metaEsdtTypes);
break;
default:
types.push(filter.type);
}
}

elasticQuery = elasticQuery.withMustMultiShouldCondition(types, type => QueryType.Match('type', type));
}

if (filter.subType) {
elasticQuery = elasticQuery.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType, QueryOperator.AND));
}

if (identifier !== undefined) {
elasticQuery = elasticQuery.withMustCondition(QueryType.Match('identifier', identifier, QueryOperator.AND));
}
Expand Down
39 changes: 33 additions & 6 deletions src/common/indexer/elastic/elastic.indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BinaryUtils } from "@multiversx/sdk-nestjs-common";
import { ElasticService, ElasticQuery, QueryOperator, QueryType, QueryConditionOptions, ElasticSortOrder, ElasticSortProperty, TermsQuery, RangeGreaterThanOrEqual, MatchQuery } from "@multiversx/sdk-nestjs-elastic";
import { IndexerInterface } from "../indexer.interface";
import { ApiConfigService } from "src/common/api-config/api.config.service";
import { NftType } from "src/endpoints/nfts/entities/nft.type";
import { CollectionFilter } from "src/endpoints/collections/entities/collection.filter";
import { QueryPagination } from "src/common/entities/query.pagination";
import { EsdtType } from "src/endpoints/esdt/entities/esdt.type";
Expand All @@ -27,10 +26,14 @@ import { AccountHistoryFilter } from "src/endpoints/accounts/entities/account.hi
import { AccountAssets } from "src/common/assets/entities/account.assets";
import { NotWritableError } from "../entities/not.writable.error";
import { ApplicationFilter } from "src/endpoints/applications/entities/application.filter";

import { NftType } from "../entities/nft.type";

@Injectable()
export class ElasticIndexerService implements IndexerInterface {
private nonFungibleEsdtTypes: NftType[] = [NftType.NonFungibleESDT, NftType.NonFungibleESDTv2, NftType.DynamicNonFungibleESDT];
private semiFungibleEsdtTypes: NftType[] = [NftType.SemiFungibleESDT, NftType.DynamicSemiFungibleESDT];
private metaEsdtTypes: NftType[] = [NftType.MetaESDT, NftType.DynamicMetaESDT];

constructor(
private readonly apiConfigService: ApiConfigService,
private readonly elasticService: ElasticService,
Expand Down Expand Up @@ -774,20 +777,43 @@ export class ElasticIndexerService implements IndexerInterface {
filter: CollectionFilter,
pagination: QueryPagination
): Promise<{ collection: string, count: number, balance: number }[]> {
const types = [NftType.SemiFungibleESDT, NftType.NonFungibleESDT];
let filterTypes = [...this.nonFungibleEsdtTypes, ...this.semiFungibleEsdtTypes];

if (!filter.excludeMetaESDT) {
types.push(NftType.MetaESDT);
filterTypes.push(...this.metaEsdtTypes);
}

if (filter.type && filter.type.length > 0) {
filterTypes = [];

for (const type of filter.type) {
switch (type) {
case NftType.NonFungibleESDT:
filterTypes.push(...this.nonFungibleEsdtTypes);
break;
case NftType.SemiFungibleESDT:
filterTypes.push(...this.semiFungibleEsdtTypes);
break;
case NftType.MetaESDT:
filterTypes.push(...this.metaEsdtTypes);
break;
default:
filterTypes.push(type);
}
}
}

console.log({ subType: filter.subType });

const elasticQuery = ElasticQuery.create()
.withMustExistCondition('identifier')
.withMustMatchCondition('address', address)
.withPagination({ from: 0, size: 0 })
.withMustMatchCondition('token', filter.collection, QueryOperator.AND)
.withMustMultiShouldCondition(filter.identifiers, identifier => QueryType.Match('token', identifier, QueryOperator.AND))
.withSearchWildcardCondition(filter.search, ['token', 'name'])
.withMustMultiShouldCondition(filter.type, type => QueryType.Match('type', type))
.withMustMultiShouldCondition(types, type => QueryType.Match('type', type))
.withMustMultiShouldCondition(filterTypes, type => QueryType.Match('type', type))
.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType))
.withExtra({
aggs: {
collections: {
Expand Down Expand Up @@ -828,6 +854,7 @@ export class ElasticIndexerService implements IndexerInterface {
return data;
}


async getAssetsForToken(identifier: string): Promise<any> {
return await this.elasticService.getCustomValue('tokens', identifier, 'assets');
}
Expand Down
Loading

0 comments on commit 595359b

Please sign in to comment.