Skip to content

Commit c8351ff

Browse files
authored
Cherry pick #840 (#843)
Remove unnecessary call when details not requested (#842) Signed-off-by: lukelee-sl <[email protected]> Signed-off-by: lukelee-sl <[email protected]> Signed-off-by: lukelee-sl <[email protected]>
1 parent 95b3af3 commit c8351ff

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,13 @@ export class EthImpl implements Eth {
12301230
for (const result of contractResults.results) {
12311231
// depending on stage of contract execution revert the result.to value may be null
12321232
if (!_.isNil(result.to)) {
1233-
const transaction = await this.getTransactionFromContractResult(result.to, result.timestamp, requestId);
1234-
if (transaction !== null) {
1235-
showDetails ? transactionObjects.push(transaction) : transactionHashes.push(transaction.hash);
1233+
if(showDetails) {
1234+
const transaction = await this.getTransactionFromContractResult(result.to, result.timestamp, requestId);
1235+
if (transaction !== null) {
1236+
transactionObjects.push(transaction);
1237+
}
1238+
} else {
1239+
transactionHashes.push(result.hash);
12361240
}
12371241
}
12381242
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,6 @@ describe('Eth calls using MirrorNode', async function () {
652652
// mirror node request mocks
653653
mock.onGet(`blocks/${blockNumber}`).reply(200, defaultBlock);
654654
mock.onGet(`contracts/results?timestamp=gte:${defaultBlock.timestamp.from}&timestamp=lte:${defaultBlock.timestamp.to}&limit=100&order=asc`).reply(200, defaultContractResults);
655-
mock.onGet(`contracts/${contractAddress1}/results/${contractTimestamp1}`).reply(200, defaultDetailedContractResults);
656-
mock.onGet(`contracts/${contractAddress2}/results/${contractTimestamp2}`).reply(200, defaultDetailedContractResults);
657655
mock.onGet('network/fees').reply(200, defaultNetworkFees);
658656
const result = await ethImpl.getBlockByNumber(EthImpl.numberTo0x(blockNumber), false);
659657
expect(result).to.exist;
@@ -667,7 +665,7 @@ describe('Eth calls using MirrorNode', async function () {
667665
expect(result.timestamp).equal(blockTimestampHex);
668666
expect(result.transactions.length).equal(2);
669667
expect((result.transactions[0] as string)).equal(contractHash1);
670-
expect((result.transactions[1] as string)).equal(contractHash1);
668+
expect((result.transactions[1] as string)).equal(contractHash2);
671669

672670
// verify expected constants
673671
verifyBlockConstants(result);
@@ -826,8 +824,6 @@ describe('Eth calls using MirrorNode', async function () {
826824
// mirror node request mocks
827825
mock.onGet(`blocks/${blockHash}`).reply(200, defaultBlock);
828826
mock.onGet(`contracts/results?timestamp=gte:${defaultBlock.timestamp.from}&timestamp=lte:${defaultBlock.timestamp.to}&limit=100&order=asc`).reply(200, defaultContractResults);
829-
mock.onGet(`contracts/${contractAddress1}/results/${contractTimestamp1}`).reply(200, defaultDetailedContractResults);
830-
mock.onGet(`contracts/${contractAddress2}/results/${contractTimestamp2}`).reply(200, defaultDetailedContractResults);
831827
mock.onGet('network/fees').reply(200, defaultNetworkFees);
832828

833829
const result = await ethImpl.getBlockByHash(blockHash, false);
@@ -842,7 +838,7 @@ describe('Eth calls using MirrorNode', async function () {
842838
expect(result.timestamp).equal(blockTimestampHex);
843839
expect(result.transactions.length).equal(2);
844840
expect((result.transactions[0] as string)).equal(contractHash1);
845-
expect((result.transactions[1] as string)).equal(contractHash1);
841+
expect((result.transactions[1] as string)).equal(contractHash2);
846842

847843
// verify expected constants
848844
verifyBlockConstants(result);

0 commit comments

Comments
 (0)