Skip to content

Commit f72b482

Browse files
use events index instead of logs
1 parent d3776fc commit f72b482

7 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/common/indexer/elastic/elastic.indexer.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,14 @@ export class ElasticIndexerService implements IndexerInterface {
594594
async getTransactionLogs(hashes: string[]): Promise<any[]> {
595595
const queries = [];
596596
for (const hash of hashes) {
597-
queries.push(QueryType.Match('_id', hash));
597+
queries.push(QueryType.Match('txHash', hash));
598598
}
599599

600600
const elasticQueryLogs = ElasticQuery.create()
601601
.withPagination({ from: 0, size: 10000 })
602602
.withCondition(QueryConditionOptions.should, queries);
603603

604-
return await this.elasticService.getList('logs', 'id', elasticQueryLogs);
604+
return await this.elasticService.getList('events', 'id', elasticQueryLogs);
605605
}
606606

607607
async getTransactionScResults(txHash: string): Promise<any[]> {

src/common/indexer/entities/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export { Tag } from './tag';
1212
export { Token } from './token';
1313
export { TokenAccount, TokenType } from './token.account';
1414
export { Transaction } from './transaction';
15-
export { TransactionLog, TransactionLogEvent } from './transaction.log';
15+
export { TransactionLog, TransactionLogEvent, ElasticTransactionLogEvent } from './transaction.log';
1616
export { TransactionReceipt } from './transaction.receipt';

src/common/indexer/entities/transaction.log.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ export interface TransactionLogEvent {
1313
data?: string;
1414
order: number;
1515
}
16+
17+
export interface ElasticTransactionLogEvent {
18+
address: string;
19+
identifier: string;
20+
topics: string[];
21+
data?: string;
22+
order: number;
23+
txHash: string;
24+
originalTxHash: string;
25+
logAddress: string;
26+
additionalData?: string[];
27+
}

src/common/indexer/indexer.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { TokenWithRolesFilter } from "src/endpoints/tokens/entities/token.with.r
1212
import { TransactionFilter } from "src/endpoints/transactions/entities/transaction.filter";
1313
import { TokenAssets } from "../assets/entities/token.assets";
1414
import { QueryPagination } from "../entities/query.pagination";
15-
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, TransactionLog, TransactionReceipt } from "./entities";
15+
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, ElasticTransactionLogEvent, TransactionReceipt } from "./entities";
1616
import { AccountAssets } from "../assets/entities/account.assets";
1717
import { ProviderDelegators } from "./entities/provider.delegators";
1818
import { ApplicationFilter } from "src/endpoints/applications/entities/application.filter";
@@ -134,7 +134,7 @@ export interface IndexerInterface {
134134

135135
getTokensForAddress(address: string, queryPagination: QueryPagination, filter: TokenFilter): Promise<Token[]>
136136

137-
getTransactionLogs(hashes: string[]): Promise<TransactionLog[]>
137+
getTransactionLogs(hashes: string[]): Promise<ElasticTransactionLogEvent[]>
138138

139139
getTransactionScResults(txHash: string): Promise<ScResult[]>
140140

src/common/indexer/indexer.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TransactionFilter } from "src/endpoints/transactions/entities/transacti
1111
import { MetricsEvents } from "src/utils/metrics-events.constants";
1212
import { TokenAssets } from "../assets/entities/token.assets";
1313
import { QueryPagination } from "../entities/query.pagination";
14-
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, TransactionLog, TransactionReceipt } from "./entities";
14+
import { Account, AccountHistory, AccountTokenHistory, Block, Collection, MiniBlock, Operation, Round, ScDeploy, ScResult, Tag, Token, TokenAccount, Transaction, ElasticTransactionLogEvent, TransactionReceipt } from "./entities";
1515
import { IndexerInterface } from "./indexer.interface";
1616
import { LogPerformanceAsync } from "src/utils/log.performance.decorator";
1717
import { AccountQueryOptions } from "src/endpoints/accounts/entities/account.query.options";
@@ -302,7 +302,7 @@ export class IndexerService implements IndexerInterface {
302302
}
303303

304304
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
305-
async getTransactionLogs(hashes: string[]): Promise<TransactionLog[]> {
305+
async getTransactionLogs(hashes: string[]): Promise<ElasticTransactionLogEvent[]> {
306306
return await this.indexerInterface.getTransactionLogs(hashes);
307307
}
308308

src/endpoints/transactions/entities/transaction.log.event.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class TransactionLogEvent {
2121
@ApiProperty()
2222
data: string = '';
2323

24+
@ApiProperty()
25+
order: number = 0;
26+
2427
@ApiProperty()
2528
additionalData: string[] | undefined = undefined;
2629
}

src/endpoints/transactions/transaction.get.service.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,34 @@ export class TransactionGetService {
5252
}
5353

5454
private async getTransactionLogsFromElasticInternal(hashes: string[]): Promise<any[]> {
55-
return await this.indexerService.getTransactionLogs(hashes);
55+
const rawHits = await this.indexerService.getTransactionLogs(hashes);
56+
57+
const logsMap: Map<string, TransactionLog> = new Map();
58+
59+
for (const source of rawHits) {
60+
const txHash = source.txHash;
61+
62+
if (!logsMap.has(txHash)) {
63+
logsMap.set(txHash, new TransactionLog({
64+
id: txHash,
65+
address: source.address,
66+
events: [],
67+
}));
68+
}
69+
70+
const event = {
71+
identifier: source.identifier,
72+
address: source.logAddress || source.address,
73+
data: BinaryUtils.hexToBase64(source.data ?? ''),
74+
additionalData: source.additionalData?.map(d => BinaryUtils.hexToBase64(d)),
75+
topics: source.topics?.map(t => BinaryUtils.hexToBase64(t)),
76+
order: source.order ?? 0,
77+
};
78+
79+
logsMap.get(txHash)?.events.push(ApiUtils.mergeObjects(new TransactionLogEvent(), event));
80+
}
81+
82+
return Array.from(logsMap.values());
5683
}
5784

5885
async getTransactionScResultsFromElastic(txHash: string): Promise<SmartContractResult[]> {

0 commit comments

Comments
 (0)