Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ export class BlockService implements IBlockService {
timestamp: [`lte:${block.timestamp.to}`, `gte:${block.timestamp.from}`],
};

const contractResults = await this.mirrorNodeClient.getContractResults(requestDetails, paramTimestamp);
if (!contractResults || contractResults.length === 0) {
const [contractResults, logs] = await Promise.all([
this.mirrorNodeClient.getContractResults(requestDetails, paramTimestamp),
this.common.getLogsWithParams(null, paramTimestamp, requestDetails),
]);

if ((!contractResults || contractResults.length === 0) && logs.length == 0) {
return [];
}

const receipts: ITransactionReceipt[] = [];
const effectiveGas = numberTo0x(await this.common.getGasPriceInWeibars(block.timestamp.from.split('.')[0]));

const logs = await this.common.getLogsWithParams(null, paramTimestamp, requestDetails);

const logsByHash = new Map<string, Log[]>();
for (const log of logs) {
const existingLogs = logsByHash.get(log.transactionHash) || [];
Expand Down
2 changes: 2 additions & 0 deletions packages/relay/tests/lib/eth/eth_getBlockReceipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ describe('@ethGetBlockReceipts using MirrorNode', async function () {

it('should return empty array for block with no transactions', async function () {
restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL_2).reply(200, JSON.stringify({ results: [] }));
restMock.onGet(CONTRACT_RESULTS_LOGS_WITH_FILTER_URL_2).reply(200, JSON.stringify({ results: [] }));
restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, JSON.stringify(DEFAULT_BLOCK));

const receipts = await ethImpl.getBlockReceipts(BLOCK_HASH, requestDetails);
Expand Down Expand Up @@ -320,6 +321,7 @@ describe('@ethGetBlockReceipts using MirrorNode', async function () {
describe('Error cases', () => {
it('should handle transactions with no contract results', async function () {
restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL_2).reply(200, JSON.stringify({ results: [] }));
restMock.onGet(CONTRACT_RESULTS_LOGS_WITH_FILTER_URL_2).reply(200, JSON.stringify({ results: [] }));
restMock.onGet(BLOCKS_LIMIT_ORDER_URL).reply(200, JSON.stringify({ blocks: [DEFAULT_BLOCK] }));
restMock.onGet(`blocks/${BLOCK_NUMBER}`).reply(200, JSON.stringify(DEFAULT_BLOCK));

Expand Down
24 changes: 24 additions & 0 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,30 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
]);
expect(res).to.be.null;
});

it('should execute "eth_getBlockReceipts" for a block that contains synthetic transaction', async function() {
const tokenId = await servicesNode.createToken(1000);
await accounts[2].client.associateToken(tokenId);
const transaction = new TransferTransaction()
.addTokenTransfer(tokenId, servicesNode._thisAccountId(), -10)
.addTokenTransfer(tokenId, accounts[2].accountId, 10)
.setTransactionMemo('Relay test token transfer');
const resp = await transaction.execute(servicesNode.client);
await resp.getRecord(servicesNode.client);
await Utils.wait(1000);
const logsRes = await mirrorNode.get(`/contracts/results/logs?limit=1`);
const blockNumber = logsRes.logs[0].block_number;
const formattedBlockNumber = prepend0x(blockNumber.toString(16));
const contractId = logsRes.logs[0].contract_id;
const transactionHash = logsRes.logs[0].transaction_hash;
if (contractId !== tokenId.toString()) {
return;
}

const receipts = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_RECEIPTS, [formattedBlockNumber]);
expect(receipts).to.not.be.empty;
expect(receipts.filter(receipt => receipt.transactionHash === transactionHash)).to.not.be.empty;
});
});

describe('Transaction related RPC Calls', () => {
Expand Down
Loading