Skip to content

Commit c850092

Browse files
committed
Revert "fix: resolved evm addresses for from and to addresses in returned transactions (#2185)"
This reverts commit 7b12027.
1 parent 6163415 commit c850092

File tree

2 files changed

+25
-95
lines changed

2 files changed

+25
-95
lines changed

packages/relay/src/lib/eth.ts

+25-69
Original file line numberDiff line numberDiff line change
@@ -1231,19 +1231,19 @@ export class EthImpl implements Eth {
12311231
this.logger.trace(
12321232
`${requestIdPrefix} getTransactionByBlockHashAndIndex(hash=${blockHash}, index=${transactionIndex})`,
12331233
);
1234-
1235-
try {
1236-
return await this.getTransactionByBlockHashOrBlockNumAndIndex(
1237-
{ title: 'blockHash', value: blockHash },
1238-
transactionIndex,
1234+
return this.mirrorNodeClient
1235+
.getContractResults(
1236+
{ blockHash: blockHash, transactionIndex: Number(transactionIndex) },
1237+
undefined,
12391238
requestIdPrefix,
1240-
);
1241-
} catch (error) {
1242-
throw this.common.genericErrorHandler(
1243-
error,
1244-
`${requestIdPrefix} Failed to retrieve contract result for blockHash ${blockHash} and index=${transactionIndex}`,
1245-
);
1246-
}
1239+
)
1240+
.then((contractResults) => formatContractResult(contractResults[0] ?? null))
1241+
.catch((error: any) => {
1242+
throw this.common.genericErrorHandler(
1243+
error,
1244+
`${requestIdPrefix} Failed to retrieve contract result for blockHash ${blockHash} and index=${transactionIndex}`,
1245+
);
1246+
});
12471247
}
12481248

12491249
/**
@@ -1261,19 +1261,19 @@ export class EthImpl implements Eth {
12611261
`${requestIdPrefix} getTransactionByBlockNumberAndIndex(blockNum=${blockNumOrTag}, index=${transactionIndex})`,
12621262
);
12631263
const blockNum = await this.translateBlockTag(blockNumOrTag, requestIdPrefix);
1264-
1265-
try {
1266-
return await this.getTransactionByBlockHashOrBlockNumAndIndex(
1267-
{ title: 'blockNumber', value: blockNum },
1268-
transactionIndex,
1264+
return this.mirrorNodeClient
1265+
.getContractResults(
1266+
{ blockNumber: blockNum, transactionIndex: Number(transactionIndex) },
1267+
undefined,
12691268
requestIdPrefix,
1270-
);
1271-
} catch (error) {
1272-
throw this.common.genericErrorHandler(
1273-
error,
1274-
`${requestIdPrefix} Failed to retrieve contract result for blockNum ${blockNum} and index=${transactionIndex}`,
1275-
);
1276-
}
1269+
)
1270+
.then((contractResults) => formatContractResult(contractResults[0] ?? null))
1271+
.catch((e: any) => {
1272+
throw this.common.genericErrorHandler(
1273+
e,
1274+
`${requestIdPrefix} Failed to retrieve contract result for blockNum ${blockNum} and index=${transactionIndex}`,
1275+
);
1276+
});
12771277
}
12781278

12791279
/**
@@ -1500,40 +1500,6 @@ export class EthImpl implements Eth {
15001500
}
15011501
}
15021502

1503-
/**
1504-
* Gets transactions by block hash or block number and index with resolved EVM addresses
1505-
* @param blockParam
1506-
* @param transactionIndex
1507-
* @param requestIdPrefix
1508-
* @returns Promise<Transaction | null>
1509-
*/
1510-
private async getTransactionByBlockHashOrBlockNumAndIndex(
1511-
blockParam: {
1512-
title: 'blockHash' | 'blockNumber';
1513-
value: string | number;
1514-
},
1515-
transactionIndex: string,
1516-
requestIdPrefix?: string,
1517-
): Promise<Transaction | null> {
1518-
const contractResults = await this.mirrorNodeClient.getContractResults(
1519-
{
1520-
[blockParam.title]: blockParam.value,
1521-
transactionIndex: Number(transactionIndex),
1522-
},
1523-
undefined,
1524-
requestIdPrefix,
1525-
);
1526-
1527-
if (!contractResults[0]) return null;
1528-
1529-
const resolvedToAddress = await this.resolveEvmAddress(contractResults[0].to, requestIdPrefix);
1530-
const resolvedFromAddress = await this.resolveEvmAddress(contractResults[0].from, requestIdPrefix, [
1531-
constants.TYPE_ACCOUNT,
1532-
]);
1533-
1534-
return formatContractResult({ ...contractResults[0], from: resolvedFromAddress, to: resolvedToAddress });
1535-
}
1536-
15371503
// according to EIP-1898 (https://eips.ethereum.org/EIPS/eip-1898) block param can either be a string (blockNumber or Block Tag) or an object (blockHash or blockNumber)
15381504
private async extractBlockNumberOrTag(
15391505
blockParam: string | object | null,
@@ -2038,18 +2004,8 @@ export class EthImpl implements Eth {
20382004
throw predefined.MAX_BLOCK_SIZE(blockResponse.count);
20392005
}
20402006

2041-
// prepare transactionArray
2042-
let transactionArray: any[] = [];
2043-
for (const contractResult of contractResults) {
2044-
contractResult.from = await this.resolveEvmAddress(contractResult.from, requestIdPrefix, [
2045-
constants.TYPE_ACCOUNT,
2046-
]);
2047-
contractResult.to = await this.resolveEvmAddress(contractResult.to, requestIdPrefix);
2048-
2049-
transactionArray.push(showDetails ? formatContractResult(contractResult) : contractResult.hash);
2050-
}
2051-
20522007
const blockHash = toHash32(blockResponse.hash);
2008+
const transactionArray = contractResults.map((cr) => (showDetails ? formatContractResult(cr) : cr.hash));
20532009
// Gating feature in case of unexpected behavior with other apps.
20542010
if (this.shouldPopulateSyntheticContractResults) {
20552011
this.filterAndPopulateSyntheticContractResults(showDetails, logs, transactionArray, requestIdPrefix);

packages/server/tests/acceptance/rpc_batch1.spec.ts

-26
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,6 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
6161
const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(Constants.TINYBAR_TO_WEIBAR_COEF));
6262
const sendRawTransaction = relay.sendRawTransaction;
6363

64-
/**
65-
* resolves long zero addresses to EVM addresses by querying mirror node
66-
* @param tx: any - supposedly a proper transaction that has `from` and `to` fields
67-
* @returns Promise<{from: any|null, to: any|null}>
68-
*/
69-
const resolveAccountEvmAddresses = async (tx: any) => {
70-
const fromAccountInfo = await mirrorNode.get(`/accounts/${tx.from}`);
71-
const toAccountInfo = await mirrorNode.get(`/accounts/${tx.to}`);
72-
return {
73-
from: fromAccountInfo?.evm_address ?? tx.from,
74-
to: toAccountInfo?.evm_address ?? tx.to,
75-
};
76-
};
77-
7864
describe('RPC Server Acceptance Tests', function () {
7965
this.timeout(240 * 1000); // 240 seconds
8066

@@ -102,10 +88,6 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
10288
`/contracts/${contractId}/results/${contractExecuteTimestamp}`,
10389
requestId,
10490
);
105-
106-
const resolvedAddresses = await resolveAccountEvmAddresses(mirrorContractDetails);
107-
mirrorContractDetails.from = resolvedAddresses.from;
108-
mirrorContractDetails.to = resolvedAddresses.to;
10991
});
11092

11193
this.beforeEach(async () => {
@@ -394,14 +376,6 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
394376
await mirrorNode.get(`/contracts/${res.contract_id}/results/${res.timestamp}`, requestId),
395377
);
396378
}
397-
398-
// resolve EVM address for `from` and `to`
399-
for (const mirrorTx of mirrorTransactions) {
400-
const resolvedAddresses = await resolveAccountEvmAddresses(mirrorTx);
401-
402-
mirrorTx.from = resolvedAddresses.from;
403-
mirrorTx.to = resolvedAddresses.to;
404-
}
405379
});
406380

407381
it('should execute "eth_getBlockByHash", hydrated transactions = false', async function () {

0 commit comments

Comments
 (0)