Skip to content

Commit 555385f

Browse files
authored
Add logic to handle missing transaction index (#693)
It seems occasionally `transaction_index` can be undefined from mirror node. Currently the relay throws errors in this case. While we figure out why - add logic to manage undefined transaction_index - add tests Signed-off-by: Nana Essilfie-Conduah <[email protected]>
1 parent 214ac11 commit 555385f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ export class EthImpl implements Eth {
10241024
removed: false,
10251025
topics: log.topics,
10261026
transactionHash: EthImpl.toHash32(receiptResponse.hash),
1027-
transactionIndex: EthImpl.numberTo0x(receiptResponse.transaction_index)
1027+
transactionIndex: EthImpl.nullableNumberTo0x(receiptResponse.transaction_index)
10281028
});
10291029
});
10301030

@@ -1039,7 +1039,7 @@ export class EthImpl implements Eth {
10391039
logs: logs,
10401040
logsBloom: receiptResponse.bloom === EthImpl.emptyHex ? EthImpl.emptyBloom : receiptResponse.bloom,
10411041
transactionHash: EthImpl.toHash32(receiptResponse.hash),
1042-
transactionIndex: EthImpl.numberTo0x(receiptResponse.transaction_index),
1042+
transactionIndex: EthImpl.nullableNumberTo0x(receiptResponse.transaction_index),
10431043
effectiveGasPrice: EthImpl.nanOrNumberTo0x(Number.parseInt(effectiveGas) * 10_000_000_000),
10441044
root: receiptResponse.root,
10451045
status: receiptResponse.status,
@@ -1068,7 +1068,7 @@ export class EthImpl implements Eth {
10681068
}
10691069

10701070
static nullableNumberTo0x(input: number | BigNumber): string | null {
1071-
return input === null ? null : EthImpl.numberTo0x(input);
1071+
return input == null ? null : EthImpl.numberTo0x(input);
10721072
}
10731073

10741074
static nanOrNumberTo0x(input: number | BigNumber): string {

packages/relay/tests/lib/eth.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,24 @@ describe('Eth', async function () {
25192519
if (receipt == null) return;
25202520
expect(receipt.gasUsed).to.eq("0x0");
25212521
});
2522+
2523+
it('handles missing transaction index', async function() {
2524+
// mirror node request mocks
2525+
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, {
2526+
...defaultDetailedContractResultByHash, ...{
2527+
transaction_index: undefined
2528+
}
2529+
});
2530+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(200, {
2531+
evm_address: contractEvmAddress
2532+
});
2533+
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
2534+
2535+
expect(receipt).to.exist;
2536+
2537+
expect(receipt.logs[0].transactionIndex).to.eq(null);
2538+
expect(receipt.transactionIndex).to.eq(null);
2539+
});
25222540
});
25232541

25242542
describe('eth_getTransactionByHash', async function () {

0 commit comments

Comments
 (0)