diff --git a/packages/api-server/src/db/query.ts b/packages/api-server/src/db/query.ts index 10eceab5..b1112049 100644 --- a/packages/api-server/src/db/query.ts +++ b/packages/api-server/src/db/query.ts @@ -167,12 +167,13 @@ export class Query { return await this.getTransactions({ block_number: blockNumber.toString() }); } + // Order by `transaction_index`, now only for search txs in a block private async getTransactions( params: Readonly>> ): Promise { - const transactions = await this.knex("transactions").where( - params - ); + const transactions = await this.knex("transactions") + .where(params) + .orderBy("transaction_index", "asc"); return transactions.map((tx) => formatTransaction(tx)); } @@ -225,30 +226,6 @@ export class Query { return formatTransaction(transaction); } - async getTransactionHashesByBlockHash(blockHash: Hash): Promise { - return await this.getTransactionHashes({ - block_hash: hexToBuffer(blockHash), - }); - } - - async getTransactionHashesByBlockNumber( - blockNumber: bigint - ): Promise { - return await this.getTransactionHashes({ - block_number: blockNumber.toString(), - }); - } - - private async getTransactionHashes( - params: Readonly>> - ): Promise { - const transactionHashes = await this.knex("transactions") - .select("hash") - .where(params); - - return transactionHashes.map((tx) => bufferToHex(tx.hash)); - } - async getTransactionEthHashesByBlockHash(blockHash: Hash): Promise { return await this.getTransactionEthHashes({ block_hash: hexToBuffer(blockHash), @@ -263,12 +240,14 @@ export class Query { }); } + // Order by `transaction_index`, only for search tx eth hashes in a block. private async getTransactionEthHashes( params: Readonly>> ): Promise { const transactionHashes = await this.knex("transactions") .select("eth_tx_hash") - .where(params); + .where(params) + .orderBy("transaction_index", "asc"); return transactionHashes.map((tx) => bufferToHex(tx.eth_tx_hash)); } @@ -309,9 +288,11 @@ export class Query { return undefined; } - const logs = await this.knex("logs").where({ - transaction_hash: hexToBuffer(txHash), - }); + const logs = await this.knex("logs") + .where({ + transaction_hash: hexToBuffer(txHash), + }) + .orderBy("log_index", "asc"); return [formatTransaction(tx), logs.map((log) => formatLog(log))]; }