Skip to content

Commit

Permalink
Merge branch 'development' into temp-support-for-sov-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 authored Oct 22, 2024
2 parents 2e7d58f + 595359b commit 94e2708
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 80 deletions.
41 changes: 23 additions & 18 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,8 +151,8 @@ export class ElasticIndexerHelper {
elasticQuery = elasticQuery.withMustMultiShouldCondition(types, type => QueryType.Match('type', type));
}

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

return elasticQuery.withMustMatchCondition('token', filter.collection, QueryOperator.AND)
Expand Down Expand Up @@ -182,25 +182,27 @@ export class ElasticIndexerHelper {
if (filter.type) {
const types = [];

switch (filter.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);
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.withMustCondition(QueryType.Match('type', filter.subType));
if (filter.subType) {
elasticQuery = elasticQuery.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType, QueryOperator.AND));
}

if (identifier !== undefined) {
Expand Down Expand Up @@ -308,7 +310,10 @@ export class ElasticIndexerHelper {
QueryType.Exists('canBeIgnored'),
]))
.withCondition(QueryConditionOptions.should, QueryType.Must([
QueryType.Match('type', 'normal'),
QueryType.Should([
QueryType.Match('type', 'normal'),
QueryType.Match('type', 'innerTx'),
]),
QueryType.Should([
QueryType.Match('sender', filter.address),
QueryType.Match('receiver', filter.address),
Expand Down
19 changes: 8 additions & 11 deletions src/common/indexer/elastic/elastic.indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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 { NftSubType } from '../../../endpoints/nfts/entities/nft.sub.type';
import { NftType } from "../entities/nft.type";

@Injectable()
Expand Down Expand Up @@ -778,17 +777,15 @@ export class ElasticIndexerService implements IndexerInterface {
filter: CollectionFilter,
pagination: QueryPagination
): Promise<{ collection: string, count: number, balance: number }[]> {
const types = [NftType.SemiFungibleESDT, NftType.NonFungibleESDT];
const subtypes = [NftSubType.NonFungibleESDTv2, NftSubType.DynamicSemiFungibleESDT, NftSubType.DynamicNonFungibleESDT];
let allTypes = [...types, ...subtypes];
let filterTypes = [...this.nonFungibleEsdtTypes, ...this.semiFungibleEsdtTypes];

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

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

filterTypes = [];
for (const type of filter.type) {
switch (type) {
case NftType.NonFungibleESDT:
Expand All @@ -804,19 +801,19 @@ export class ElasticIndexerService implements IndexerInterface {
filterTypes.push(type);
}
}

allTypes = filterTypes;
}


}
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(allTypes, type => QueryType.Match('type', type))
.withMustMatchCondition('type', filter.subType, QueryOperator.AND)
.withMustMultiShouldCondition(filterTypes, type => QueryType.Match('type', type))
.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType))
.withExtra({
aggs: {
collections: {
Expand Down
28 changes: 16 additions & 12 deletions src/endpoints/accounts/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class AccountController {
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('owner', ParseAddressPipe) owner?: string,
@Query('canCreate', new ParseBoolPipe) canCreate?: boolean,
@Query('canBurn', new ParseBoolPipe) canBurn?: boolean,
Expand Down Expand Up @@ -410,7 +410,7 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('owner', ParseAddressPipe) owner?: string,
@Query('canCreate', new ParseBoolPipe) canCreate?: boolean,
@Query('canBurn', new ParseBoolPipe) canBurn?: boolean,
Expand All @@ -426,7 +426,7 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('owner', ParseAddressPipe) owner?: string,
@Query('canCreate', new ParseBoolPipe) canCreate?: boolean,
@Query('canBurn', new ParseBoolPipe) canBurn?: boolean,
Expand Down Expand Up @@ -538,7 +538,7 @@ export class AccountController {
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('excludeMetaESDT', new ParseBoolPipe) excludeMetaESDT?: boolean,
): Promise<NftCollectionAccount[]> {
return await this.collectionService.getCollectionsForAddress(
Expand All @@ -558,7 +558,7 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('excludeMetaESDT', new ParseBoolPipe) excludeMetaESDT?: boolean,
): Promise<number> {
return await this.collectionService.getCollectionCountForAddress(address, new CollectionFilter({ search, type, subType, excludeMetaESDT }));
Expand All @@ -570,7 +570,7 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('excludeMetaESDT', new ParseBoolPipe) excludeMetaESDT?: boolean,
): Promise<number> {
return await this.collectionService.getCollectionCountForAddress(address, new CollectionFilter({ search, type, subType, excludeMetaESDT }));
Expand Down Expand Up @@ -622,9 +622,9 @@ export class AccountController {
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('identifiers') identifiers?: string[],
@Query('type') type?: NftType,
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('collection') collection?: string,
@Query('collections', ParseArrayPipe) collections?: string[],
@Query('name') name?: string,
Expand Down Expand Up @@ -671,6 +671,7 @@ export class AccountController {
@ApiQuery({ name: 'search', description: 'Search by collection identifier', required: false })
@ApiQuery({ name: 'identifiers', description: 'Filter by identifiers, comma-separated', required: false })
@ApiQuery({ name: 'type', description: 'Filter by type (NonFungibleESDT/SemiFungibleESDT/MetaESDT)', required: false })
@ApiQuery({ name: 'subType', description: 'Filter by subType', required: false })
@ApiQuery({ name: 'collection', description: 'Get all tokens by token collection', required: false })
@ApiQuery({ name: 'collections', description: 'Get all tokens by token collections, comma-separated', required: false })
@ApiQuery({ name: 'name', description: 'Get all nfts by name', required: false })
Expand All @@ -687,7 +688,8 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('search') search?: string,
@Query('type') type?: NftType,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('collection') collection?: string,
@Query('collections', ParseArrayPipe) collections?: string[],
@Query('name') name?: string,
Expand All @@ -704,6 +706,7 @@ export class AccountController {
search,
identifiers,
type,
subType,
collection,
collections,
name,
Expand All @@ -724,7 +727,8 @@ export class AccountController {
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('collection') collection?: string,
@Query('collections', ParseArrayPipe) collections?: string[],
@Query('name') name?: string,
Expand All @@ -737,7 +741,7 @@ export class AccountController {
@Query('scamType', new ParseEnumPipe(ScamType)) scamType?: ScamType,
@Query('timestamp', ParseIntPipe) _timestamp?: number,
): Promise<number> {
return await this.nftService.getNftCountForAddress(address, new NftFilter({ search, identifiers, type, collection, collections, name, tags, creator, hasUris, includeFlagged, excludeMetaESDT, isScam, scamType }));
return await this.nftService.getNftCountForAddress(address, new NftFilter({ search, identifiers, type, subType, collection, collections, name, tags, creator, hasUris, includeFlagged, excludeMetaESDT, isScam, scamType }));
}

@Get("/accounts/:address/nfts/:nft")
Expand Down
4 changes: 3 additions & 1 deletion src/endpoints/collections/collection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CollectionController {
@Query('search') search?: string,
@Query('identifiers') identifiers?: string[],
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumPipe(NftSubType)) subType?: NftSubType,
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('creator', ParseAddressPipe) creator?: string,
@Query('before', new ParseIntPipe) before?: number,
@Query('after', new ParseIntPipe) after?: number,
Expand Down Expand Up @@ -115,6 +115,7 @@ export class CollectionController {
async getCollectionCount(
@Query('search') search?: string,
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('subType', new ParseEnumArrayPipe(NftSubType)) subType?: NftSubType[],
@Query('creator', ParseAddressPipe) creator?: string,
@Query('before', new ParseIntPipe) before?: number,
@Query('after', new ParseIntPipe) after?: number,
Expand All @@ -129,6 +130,7 @@ export class CollectionController {
return await this.collectionService.getNftCollectionCount(new CollectionFilter({
search,
type,
subType,
canCreate: canCreate ?? creator,
before,
after,
Expand Down
5 changes: 1 addition & 4 deletions src/endpoints/collections/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ export class CollectionService {
break;
}

if (nftCollection.type !== indexedCollection.type) {
nftCollection.subType = indexedCollection.type as NftSubType;
}

nftCollection.subType = indexedCollection.type as NftSubType;
nftCollection.timestamp = indexedCollection.timestamp;

if (nftCollection.type.in(NftType.NonFungibleESDT, NftType.SemiFungibleESDT)) {
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/collections/entities/collection.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CollectionFilter {
identifiers?: string[];
search?: string;
type?: NftType[];
subType?: NftSubType;
subType?: NftSubType[];
owner?: string;
before?: number;
after?: number;
Expand Down
10 changes: 8 additions & 2 deletions src/endpoints/esdt/esdt.address.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,15 @@ export class EsdtAddressService {
}

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

nfts = nfts.filter(x => types.includes(x.type));
nfts = nfts.filter(x => nftTypes.includes(x.type));
}

if (filter.subType) {
const nftSubTypes = filter.subType ?? [];

nfts = nfts.filter(x => nftSubTypes.includes(x.subType));
}

if (filter.subType) {
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/nfts/entities/nft.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class NftFilter {

search?: string;
identifiers?: string[];
type?: NftType;
subType?: NftSubType;
type?: NftType[];
subType?: NftSubType[];
collection?: string;
collections?: string[];
tags?: string[];
Expand Down
12 changes: 12 additions & 0 deletions src/endpoints/nfts/entities/nft.sub.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { registerEnumType } from "@nestjs/graphql";

export enum NftSubType {
NonFungibleESDT = 'NonFungibleESDT',
SemiFungibleESDT = 'SemiFungibleESDT',
MetaESDT = 'MetaESDT',
NonFungibleESDTv2 = 'NonFungibleESDTv2',
DynamicNonFungibleESDT = 'DynamicNonFungibleESDT',
DynamicSemiFungibleESDT = 'DynamicSemiFungibleESDT',
Expand All @@ -11,6 +14,15 @@ registerEnumType(NftSubType, {
name: 'NftSubType',
description: 'NFT subtype.',
valuesMap: {
NonFungibleESDT: {
description: 'Non-fungible ESDT NFT type.',
},
SemiFungibleESDT: {
description: 'Semi-fungible ESDT NFT type.',
},
MetaESDT: {
description: 'Meta ESDT NFT type.',
},
NonFungibleESDTv2: {
description: 'Non-fungible ESDT v2 NFT type.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/nfts/entities/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class Nft {
type: NftType = NftType.NonFungibleESDT;

@Field(() => NftSubType, { description: "NFT sub type for the given NFT.", nullable: true })
@ApiProperty({ enum: NftSubType, nullable: true })
subType: NftSubType | undefined = undefined;
@ApiProperty({ enum: NftSubType })
subType: NftSubType = NftSubType.NonFungibleESDT;

@Field(() => String, { description: "Name for the given NFT." })
@ApiProperty({ type: String })
Expand Down
Loading

0 comments on commit 94e2708

Please sign in to comment.