Skip to content

Commit

Permalink
remove mirrorNode.ts and dependencies (#374)
Browse files Browse the repository at this point in the history
* remove mirrorNode.ts and dependencies

Signed-off-by: lukelee-sl <[email protected]>

* address sonarcloud issue

Signed-off-by: lukelee-sl <[email protected]>
  • Loading branch information
lukelee-sl committed Jul 25, 2022
1 parent d304c01 commit 9288e0c
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 200 deletions.
31 changes: 2 additions & 29 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { Eth } from '../index';
import { ContractId, Status, Hbar, EthereumTransaction } from '@hashgraph/sdk';
import { BigNumber } from '@hashgraph/sdk/lib/Transfer';
import { Logger } from 'pino';
import { Block, CachedBlock, Transaction, Log } from './model';
import { MirrorNode } from './mirrorNode';
import { Block, Transaction, Log } from './model';
import { MirrorNodeClient, SDKClient } from './clients';
import { JsonRpcError, predefined } from './errors';
import constants from './constants';
Expand Down Expand Up @@ -76,12 +75,6 @@ export class EthImpl implements Eth {
*/
private readonly sdkClient: SDKClient;

/**
* The mirror node mock
* @private
*/
private readonly mirrorNode: MirrorNode;

/**
* The interface through which we interact with the mirror node
* @private
Expand Down Expand Up @@ -109,20 +102,17 @@ export class EthImpl implements Eth {
/**
* Create a new Eth implementation.
* @param nodeClient
* @param mirrorNode
* @param mirrorNodeClient
* @param logger
* @param chain
*/
constructor(
nodeClient: SDKClient,
mirrorNode: MirrorNode,
mirrorNodeClient: MirrorNodeClient,
logger: Logger,
chain: string
) {
this.sdkClient = nodeClient;
this.mirrorNode = mirrorNode;
this.mirrorNodeClient = mirrorNodeClient;
this.logger = logger;
this.chain = chain;
Expand Down Expand Up @@ -669,24 +659,7 @@ export class EthImpl implements Eth {
if (record.ethereumHash == null) {
throw new Error('The ethereumHash can never be null for an ethereum transaction, and yet it was!!');
}
const txHash = EthImpl.prepend0x(Buffer.from(record.ethereumHash).toString('hex'));

// If the transaction succeeded, create a new block for the transaction.
const mostRecentBlock = await this.mirrorNode.getMostRecentBlock();
this.logger.debug('mostRecentBlock=%o', mostRecentBlock);
let block = mostRecentBlock;
if (record.receipt.status == Status.Success) {
block = new CachedBlock(mostRecentBlock, txHash);
this.mirrorNode.storeBlock(block);
}

// Create a receipt. Register the receipt in the cache and return the tx hash
if (block == null) {
this.logger.error('Failed to get a block for transaction');
return '';
}

return txHash;
return EthImpl.prepend0x(Buffer.from(record.ethereumHash).toString('hex'));
} catch (e) {
this.logger.error(e,
'Failed sendRawTransaction during record retrieval for transaction %s, returning computed hash', transaction);
Expand Down
143 changes: 0 additions & 143 deletions packages/relay/src/lib/mirrorNode.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/relay/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,6 @@ export class Block {
}
}

export class CachedBlock extends Block {
public readonly parentBlock:Block|null;
public readonly transactionHashes:string[] = [];

constructor(parentBlock:(null | Block), transactionHash:(string|null), args?:any) {
super(args);
this.parentBlock = parentBlock;

const num = parentBlock == null ? 0 : parentBlock.getNum() + 1;
this.number = '0x' + Number(num).toString(16);
this.parentHash = parentBlock == null ? '0x0' : parentBlock.hash;
if (transactionHash) {
this.transactionHashes.push(transactionHash);
}

const numberAsString = num.toString();
const baseHash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b";
this.hash = baseHash.slice(0, baseHash.length - numberAsString.length) + numberAsString;
}
}

export class Receipt {
public readonly transactionHash:string;
public readonly transactionIndex:string;
Expand Down
4 changes: 0 additions & 4 deletions packages/relay/src/lib/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { NetImpl } from './net';
import { EthImpl } from './eth';
import { AccountId, Client, PrivateKey } from '@hashgraph/sdk';
import { Logger } from 'pino';
import { MirrorNode } from './mirrorNode';
import { MirrorNodeClient, SDKClient } from './clients';
import { Registry } from 'prom-client';

Expand Down Expand Up @@ -57,8 +56,6 @@ export class RelayImpl implements Relay {
this.web3Impl = new Web3Impl(this.clientMain);
this.netImpl = new NetImpl(this.clientMain, chainId);

const mirrorNode = new MirrorNode(logger.child({ name: `mirror-node` }));

const mirrorNodeClient = new MirrorNodeClient(
process.env.MIRROR_NODE_URL || '',
logger.child({ name: `mirror-node` }),
Expand All @@ -69,7 +66,6 @@ export class RelayImpl implements Relay {

this.ethImpl = new EthImpl(
sdkClient,
mirrorNode,
mirrorNodeClient,
logger.child({ name: 'relay-eth' }),
chainId);
Expand Down
5 changes: 2 additions & 3 deletions packages/relay/tests/lib/eth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dotenv.config({ path: path.resolve(__dirname, '../test.env') });
import { RelayImpl } from '@hashgraph/json-rpc-relay';
import { EthImpl } from '../../src/lib/eth';
import { MirrorNodeClient } from '../../src/lib/clients/mirrorNodeClient';
import { MirrorNode } from '../../src/lib/mirrorNode';
import { expectUnsupportedMethod } from '../helpers';

import pino from 'pino';
Expand Down Expand Up @@ -92,7 +91,7 @@ describe('Eth calls using MirrorNode', async function () {
mirrorNodeInstance = new MirrorNodeClient(process.env.MIRROR_NODE_URL, logger.child({ name: `mirror-node` }), registry, instance);
sdkClientStub = sinon.createStubInstance(SDKClient);
// @ts-ignore
ethImpl = new EthImpl(sdkClientStub, new MirrorNode(logger.child({ name: `mirror-node-faux` })), mirrorNodeInstance, logger, '0x12a');
ethImpl = new EthImpl(sdkClientStub, mirrorNodeInstance, logger, '0x12a');
});

this.beforeEach(() => {
Expand Down Expand Up @@ -1326,7 +1325,7 @@ describe('Eth', async function () {
let ethImpl: EthImpl;
this.beforeAll(() => {
// @ts-ignore
ethImpl = new EthImpl(null, null, mirrorNodeInstance, logger);
ethImpl = new EthImpl(null, mirrorNodeInstance, logger);
});

const defaultTxHash = '0x4a563af33c4871b51a8b108aa2fe1dd5280a30dfb7236170ae5e5e7957eb6392';
Expand Down

0 comments on commit 9288e0c

Please sign in to comment.