Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

API-375 add support for MetaESDT assets in ES #1435

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/common/indexer/elastic/elastic.indexer.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,24 @@ export class ElasticIndexerHelper {
elasticQuery = elasticQuery.withMustMultiShouldCondition(filter.subType, subType => QueryType.Match('type', subType));
}

if (filter.name) {
elasticQuery = elasticQuery.withMustWildcardCondition('api_assets.name', filter.name);
}

if (filter.hasAssets !== undefined) {
if (filter.hasAssets) {
elasticQuery = elasticQuery.withMustExistCondition('api_assets');
} else {
elasticQuery = elasticQuery.withMustNotExistCondition('api_assets');
}
}

if (filter.search) {
elasticQuery = elasticQuery.withSearchWildcardCondition(filter.search, ['token', 'name', 'api_assets.name']);
}

return elasticQuery.withMustMatchCondition('token', filter.collection, QueryOperator.AND)
.withMustMultiShouldCondition(filter.identifiers, identifier => QueryType.Match('token', identifier, QueryOperator.AND))
.withSearchWildcardCondition(filter.search, ['token', 'name']);
.withMustMultiShouldCondition(filter.identifiers, identifier => QueryType.Match('token', identifier, QueryOperator.AND));
}

private getRoleCondition(query: ElasticQuery, name: string, address: string | undefined, value: string | boolean) {
Expand Down
13 changes: 13 additions & 0 deletions src/common/indexer/elastic/elastic.indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,19 @@ export class ElasticIndexerService implements IndexerInterface {
return await this.elasticService.setCustomValues('accounts', address, { assets });
}

async setCollectionAssetsFields(identifier: string, assets: any): Promise<void> {
const collection = await this.getCollection(identifier);
if (!collection) {
return;
}

if (this.metaEsdtTypes.includes(collection.type as NftType)) {
return await this.elasticService.setCustomValues('tokens', identifier, {
api_assets: assets,
});
}
}

async ensureAccountsWritable(): Promise<void> {
await this.ensureCollectionWritable('accounts');
}
Expand Down
1 change: 1 addition & 0 deletions src/common/indexer/entities/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface Collection {
api_holderCount?: number;
nft_scamInfoType?: string;
nft_scamInfoDescription?: string;
api_assets?: any;
}
2 changes: 2 additions & 0 deletions src/common/indexer/indexer.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export interface IndexerInterface {

setAccountAssetsFields(address: string, assets: AccountAssets): Promise<void>

setCollectionAssetsFields(identifier: string, assets: any): Promise<void>

ensureAccountsWritable(): Promise<void>

ensureTokensWritable(): Promise<void>
Expand Down
5 changes: 5 additions & 0 deletions src/common/indexer/indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,9 @@ export class IndexerService implements IndexerInterface {
async getEventsCount(filter: EventsFilter): Promise<number> {
return await this.indexerInterface.getEventsCount(filter);
}

@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
async setCollectionAssetsFields(identifier: string, assets: any): Promise<void> {
return await this.indexerInterface.setCollectionAssetsFields(identifier, assets);
}
}
3 changes: 3 additions & 0 deletions src/endpoints/collections/entities/collection.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export class CollectionFilter {

sort?: SortCollections;
order?: SortOrder;

name?: string;
hasAssets?: boolean;
}
Loading