Skip to content

Commit 2a97070

Browse files
authored
Remove eth.getLogEvmAddress() (#768)
* Remove methods Signed-off-by: nikolay <[email protected]> * Edit eth.ts Signed-off-by: nikolay <[email protected]> * Edit mirror node version Signed-off-by: nikolay <[email protected]> * Edit test Signed-off-by: nikolay <[email protected]> * Edit test Signed-off-by: nikolay <[email protected]> * Edit test Signed-off-by: nikolay <[email protected]> Signed-off-by: nikolay <[email protected]>
1 parent 9e18be6 commit 2a97070

File tree

2 files changed

+17
-50
lines changed

2 files changed

+17
-50
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class EthImpl implements Eth {
9393
*
9494
* @private
9595
*/
96-
private readonly cache;
96+
private readonly cache;
9797

9898
/**
9999
* The sdk client use for connecting to both the consensus nodes and mirror node. The account
@@ -583,10 +583,10 @@ export class EthImpl implements Eth {
583583
}
584584

585585
let transactionsInTimeWindow = await this.mirrorNodeClient.getTransactionsForAccount(
586-
mirrorAccount.account,
587-
block.timestamp.to,
588-
currentTimestamp,
589-
requestId
586+
mirrorAccount.account,
587+
block.timestamp.to,
588+
currentTimestamp,
589+
requestId
590590
);
591591

592592
for(const tx of transactionsInTimeWindow) {
@@ -665,7 +665,7 @@ export class EthImpl implements Eth {
665665
}
666666
else if (result?.type === constants.TYPE_CONTRACT) {
667667
if (result?.entity.runtime_bytecode !== EthImpl.emptyHex) {
668-
return result?.entity.runtime_bytecode;
668+
return result?.entity.runtime_bytecode;
669669
}
670670
}
671671
}
@@ -836,8 +836,8 @@ export class EthImpl implements Eth {
836836
try {
837837
const result = await this.mirrorNodeClient.resolveEntityType(address, requestId);
838838
if (result?.type === constants.TYPE_ACCOUNT) {
839-
const accountInfo = await this.sdkClient.getAccountInfo(result?.entity.account, EthImpl.ethGetTransactionCount, requestId);
840-
return EthImpl.numberTo0x(Number(accountInfo.ethereumNonce));
839+
const accountInfo = await this.sdkClient.getAccountInfo(result?.entity.account, EthImpl.ethGetTransactionCount, requestId);
840+
return EthImpl.numberTo0x(Number(accountInfo.ethereumNonce));
841841
}
842842
else if (result?.type === constants.TYPE_CONTRACT) {
843843
return EthImpl.numberTo0x(1);
@@ -1414,7 +1414,7 @@ export class EthImpl implements Eth {
14141414
return EMPTY_RESPONSE;
14151415
}
14161416
} else if ( !(await this.validateBlockRangeAndAddTimestampToParams(params, fromBlock, toBlock, requestId)) ) {
1417-
return EMPTY_RESPONSE;
1417+
return EMPTY_RESPONSE;
14181418
}
14191419

14201420
this.addTopicsToParams(params, topics);
@@ -1435,7 +1435,7 @@ export class EthImpl implements Eth {
14351435
for(const log of logResults) {
14361436
logs.push(
14371437
new Log({
1438-
address: await this.getLogEvmAddress(log.address, requestId) || log.address,
1438+
address: log.address,
14391439
blockHash: EthImpl.toHash32(log.block_hash),
14401440
blockNumber: EthImpl.numberTo0x(log.block_number),
14411441
data: log.data,
@@ -1457,21 +1457,6 @@ export class EthImpl implements Eth {
14571457
return EthImpl.zeroHex;
14581458
}
14591459

1460-
private async getLogEvmAddress(address: string, requestId: string | undefined) {
1461-
const cachedLabel = `getLogEvmAddress.${address}`;
1462-
let contractAddress = this.cache.get(cachedLabel);
1463-
1464-
// If contractAddress === undefined it means there's no cache record
1465-
// and a mirror node request should be executed.
1466-
if (contractAddress === undefined) {
1467-
const contract = await this.mirrorNodeClient.getContract(address, requestId);
1468-
contractAddress = contract.evm_address;
1469-
this.cache.set(cachedLabel, contractAddress);
1470-
}
1471-
1472-
return contractAddress;
1473-
}
1474-
14751460
static isArrayNonEmpty(input: any): boolean {
14761461
return Array.isArray(input) && input.length > 0;
14771462
}

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('Eth calls using MirrorNode', async function () {
261261

262262
const defaultLogs1 = [
263263
{
264-
"address": "0x0000000000000000000000000000000002131951",
264+
"address": "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69",
265265
"bloom": logBloom1,
266266
"contract_id": contractId1,
267267
"data": "0x",
@@ -275,7 +275,7 @@ describe('Eth calls using MirrorNode', async function () {
275275
"transaction_index": 1
276276
},
277277
{
278-
"address": "0x0000000000000000000000000000000002131951",
278+
"address": "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69",
279279
"bloom": logBloom2,
280280
"contract_id": contractId1,
281281
"data": "0x",
@@ -292,7 +292,7 @@ describe('Eth calls using MirrorNode', async function () {
292292

293293
const defaultLogs2 = [
294294
{
295-
"address": "0x0000000000000000000000000000000002131951",
295+
"address": "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69",
296296
"bloom": logBloom3,
297297
"contract_id": contractId1,
298298
"data": "0x",
@@ -309,7 +309,7 @@ describe('Eth calls using MirrorNode', async function () {
309309

310310
const defaultLogs3 = [
311311
{
312-
"address": "0x0000000000000000000000000000000002131951",
312+
"address": "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69",
313313
"bloom": logBloom4,
314314
"contract_id": contractId2,
315315
"data": "0x",
@@ -326,7 +326,7 @@ describe('Eth calls using MirrorNode', async function () {
326326

327327
const defaultLogs4 = [
328328
{
329-
"address": "0x0000000000000000000000000000000002131951",
329+
"address": "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69",
330330
"bloom": logBloom4,
331331
"contract_id": contractId2,
332332
"data": "0x",
@@ -1679,15 +1679,15 @@ describe('Eth calls using MirrorNode', async function () {
16791679
it('should be able to return more than two logs with limit of two per request', async function () {
16801680
const unfilteredLogs = {
16811681
logs: [
1682-
{...defaultLogs.logs[0], address: "0x0000000000000000000000000000000002131951"},
1682+
{...defaultLogs.logs[0], address: "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69"},
16831683
{...defaultLogs.logs[1], address: "0x0000000000000000000000000000000002131952"},
16841684
{...defaultLogs.logs[2], address: "0x0000000000000000000000000000000002131953"},
16851685
{...defaultLogs.logs[3], address: "0x0000000000000000000000000000000002131954"}
16861686
]
16871687
}
16881688
const filteredLogs = {
16891689
logs: [
1690-
{...defaultLogs.logs[0], address: "0x0000000000000000000000000000000002131951"},
1690+
{...defaultLogs.logs[0], address: "0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69"},
16911691
{...defaultLogs.logs[1], address: "0x0000000000000000000000000000000002131952"}
16921692
],
16931693
links: {next: 'contracts/results/logs?limit=2&order=desc&timestamp=lte:1668432962.375200975&index=lt:0'}
@@ -1739,24 +1739,6 @@ describe('Eth calls using MirrorNode', async function () {
17391739
expect(result[0].address).to.eq(defaultEvmAddress);
17401740
});
17411741

1742-
it('Should cache contracts/contractIdOrAddress request', async function () {
1743-
mock.onGet("blocks?limit=1&order=desc").reply(200, { blocks: [defaultBlock] });
1744-
mock.onGet(`contracts/results/logs?timestamp=gte:${defaultBlock.timestamp.from}&timestamp=lte:${defaultBlock.timestamp.to}&limit=100&order=asc`).reply(200, defaultLogs);
1745-
mock.onGet(`contracts/${defaultLogs.logs[0].address}`).replyOnce(200, defaultContract); // This mock will fire only once, if the request is not cached, the test will fail with no mock error
1746-
1747-
const result = await ethImpl.getLogs(null, null, null, null, null);
1748-
1749-
expect(cache.keyList.includes('getLogEvmAddress.0x0000000000000000000000000000000002131951')).to.be.true;
1750-
1751-
expect(result).to.exist;
1752-
expect(result.length).to.eq(4);
1753-
1754-
expectLogData1(result[0]);
1755-
expectLogData2(result[1]);
1756-
expectLogData3(result[2]);
1757-
expectLogData4(result[3]);
1758-
});
1759-
17601742
it('address filter', async function () {
17611743
const filteredLogs = {
17621744
logs: [defaultLogs.logs[0], defaultLogs.logs[1], defaultLogs.logs[2]]

0 commit comments

Comments
 (0)