diff --git a/packages/relay/src/lib/clients/mirrorNodeClient.ts b/packages/relay/src/lib/clients/mirrorNodeClient.ts index 997ba76891..bb0990ae8d 100644 --- a/packages/relay/src/lib/clients/mirrorNodeClient.ts +++ b/packages/relay/src/lib/clients/mirrorNodeClient.ts @@ -1,8 +1,8 @@ -/* - +/*- * * Hedera JSON RPC Relay * - * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -620,7 +620,10 @@ export class MirrorNodeClient { requestDetails, ); - await this.cacheService.set(cachedLabel, block, MirrorNodeClient.GET_BLOCK_ENDPOINT, requestDetails); + if (block) { + await this.cacheService.set(cachedLabel, block, MirrorNodeClient.GET_BLOCK_ENDPOINT, requestDetails); + } + return block; } diff --git a/packages/relay/src/receiptsRootUtils.ts b/packages/relay/src/receiptsRootUtils.ts index c9603de699..727eef4ba8 100644 --- a/packages/relay/src/receiptsRootUtils.ts +++ b/packages/relay/src/receiptsRootUtils.ts @@ -21,8 +21,9 @@ import { RLP } from '@ethereumjs/rlp'; import { Trie } from '@ethereumjs/trie'; import { bytesToInt, concatBytes, hexToBytes, intToBytes, intToHex } from '@ethereumjs/util'; -import { EthImpl } from './lib/eth'; + import { prepend0x } from './formatters'; +import { EthImpl } from './lib/eth'; import { Log } from './lib/model'; import { LogsBloomUtils } from './logsBloomUtils'; @@ -93,16 +94,25 @@ export class ReceiptsRootUtils { public static buildReceiptRootHashes(txHashes: string[], contractResults: any[], logs: Log[]): IReceiptRootHash[] { const receipts: IReceiptRootHash[] = []; - for (let i in txHashes) { + for (const i in txHashes) { const txHash: string = txHashes[i]; const logsPerTx: Log[] = logs.filter((log) => log.transactionHash == txHash); const crPerTx: any[] = contractResults.filter((cr) => cr.hash == txHash); + + let transactionIndex: any = null; + if (crPerTx.length && crPerTx[0].transaction_index != null) { + transactionIndex = intToHex(crPerTx[0].transaction_index); + } else if (logsPerTx.length) { + transactionIndex = logsPerTx[0].transactionIndex; + } + receipts.push({ - transactionIndex: crPerTx.length ? intToHex(crPerTx[0].transaction_index) : logsPerTx[0].transactionIndex, + transactionIndex, type: crPerTx.length && crPerTx[0].type ? intToHex(crPerTx[0].type) : null, root: crPerTx.length ? crPerTx[0].root : EthImpl.zeroHex32Byte, status: crPerTx.length ? crPerTx[0].status : EthImpl.oneHex, - cumulativeGasUsed: crPerTx.length ? intToHex(crPerTx[0].block_gas_used) : EthImpl.zeroHex, + cumulativeGasUsed: + crPerTx.length && crPerTx[0].block_gas_used ? intToHex(crPerTx[0].block_gas_used) : EthImpl.zeroHex, logsBloom: crPerTx.length ? crPerTx[0].bloom : LogsBloomUtils.buildLogsBloom(logs[0].address, logsPerTx[0].topics),