Skip to content

Commit bf98e2e

Browse files
ryanioholgerd77
authored andcommitted
remove unneeded generateCanonicalGenesis, improve comments, improve type importing
1 parent a7414cd commit bf98e2e

File tree

10 files changed

+47
-65
lines changed

10 files changed

+47
-65
lines changed

packages/client/lib/rpc/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as modules from './modules'
99
/**
1010
* get all methods. e.g., getBlockByNumber in eth module
1111
* @private
12-
* @param {Object} mod
13-
* @return {string[]}
12+
* @param Object mod
13+
* @returns string[]
1414
*/
1515
function getMethodNames(mod: any): string[] {
1616
return Object.getOwnPropertyNames(mod.prototype)

packages/client/lib/rpc/modules/admin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { bufferToHex } from 'ethereumjs-util'
2-
import { Chain } from '../../blockchain'
3-
import { EthProtocol } from '../../net/protocol'
4-
import { RlpxServer } from '../../net/server'
5-
import EthereumClient from '../../client'
6-
import { EthereumService } from '../../service'
72
import { getClientVersion } from '../../util'
83
import { middleware } from '../validation'
4+
import type { Chain } from '../../blockchain'
5+
import type { EthProtocol } from '../../net/protocol'
6+
import type { RlpxServer } from '../../net/server'
7+
import type EthereumClient from '../../client'
8+
import type { EthereumService } from '../../service'
99

1010
/**
1111
* admin_* RPC module
@@ -18,7 +18,7 @@ export class Admin {
1818

1919
/**
2020
* Create admin_* RPC module
21-
* @param {client} EthereumClient to which the module binds
21+
* @param client Client to which the module binds
2222
*/
2323
constructor(client: EthereumClient) {
2424
const service = client.services.find((s) => s.name === 'eth') as EthereumService
@@ -32,7 +32,7 @@ export class Admin {
3232
/**
3333
* Returns information about the currently running node.
3434
* see for reference: https://geth.ethereum.org/docs/rpc/ns-admin#admin_nodeinfo
35-
* @param {*} [params] An empty array
35+
* @param params An empty array
3636
*/
3737
async nodeInfo(_params: []) {
3838
const rlpxInfo = (this._client.server('rlpx') as RlpxServer).getRlpxInfo()

packages/client/lib/rpc/modules/eth.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Transaction } from '@ethereumjs/tx'
12
import {
23
Account,
34
Address,
@@ -8,13 +9,14 @@ import {
89
unpadBuffer,
910
setLengthLeft,
1011
} from 'ethereumjs-util'
11-
import { Transaction } from '@ethereumjs/tx'
1212
import { decode } from 'rlp'
13-
import { Chain } from '../../blockchain'
1413
import { middleware, validators } from '../validation'
15-
import { EthereumClient } from '../..'
1614
import { INVALID_PARAMS } from '../error-code'
1715
import { RpcCallTx } from '../types'
16+
import type { Chain } from '../../blockchain'
17+
import type { EthereumClient } from '../..'
18+
import type { EthereumService } from '../../service'
19+
import type { EthProtocol } from '../../net/protocol'
1820
import type VM from '@ethereumjs/vm'
1921

2022
/**
@@ -31,17 +33,11 @@ export class Eth {
3133
* @param client Client to which the module binds
3234
*/
3335
constructor(client: EthereumClient) {
34-
const service = client.services.find((s) => s.name === 'eth')
35-
if (!service) {
36-
throw new Error('cannot find eth service')
37-
}
36+
const service = client.services.find((s) => s.name === 'eth') as EthereumService
3837
this._chain = service.chain
3938
this._vm = (service.synchronizer as any)?.execution?.vm
4039

41-
const ethProtocol = service.protocols.find((p) => p.name === 'eth')
42-
if (!ethProtocol) {
43-
throw new Error('cannot find eth protocol')
44-
}
40+
const ethProtocol = service.protocols.find((p) => p.name === 'eth') as EthProtocol
4541
this.ethVersion = Math.max(...ethProtocol.versions)
4642

4743
this.blockNumber = middleware(this.blockNumber.bind(this), 0)
@@ -158,7 +154,8 @@ export class Eth {
158154
/**
159155
* Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.
160156
* The transaction will not be added to the blockchain.
161-
* Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.
157+
* Note that the estimate may be significantly more than the amount of gas actually used by the transaction,
158+
* for a variety of reasons including EVM mechanics and node performance.
162159
* Currently only "latest" block number is supported.
163160
* @param params An array of two parameters:
164161
* 1. The transaction object
@@ -244,7 +241,7 @@ export class Eth {
244241
* Returns information about a block by block number.
245242
* @param params An array of two parameters:
246243
* 1. integer of a block number
247-
* 2. boolean determining whether it returns full transaction objects or just the transaction hashes
244+
* 2. boolean - if true returns the full transaction objects, if false only the hashes of the transactions.
248245
*/
249246
async getBlockByNumber(params: [string, boolean]) {
250247
const [blockNumber, includeTransactions] = params
@@ -261,7 +258,7 @@ export class Eth {
261258
* Returns information about a block by hash.
262259
* @param params An array of two parameters:
263260
* 1. a block hash
264-
* 2. boolean to determine returning full transaction objects or just transaction hashes
261+
* 2. boolean - if true returns the full transaction objects, if false only the hashes of the transactions.
265262
*/
266263
async getBlockByHash(params: [string, boolean]) {
267264
const [blockHash, includeTransactions] = params
@@ -315,7 +312,7 @@ export class Eth {
315312
/**
316313
* Returns the value from a storage position at a given address.
317314
* Currently only "latest" block number is supported.
318-
* @param {Array<string>} [params] An array of three parameters:
315+
* @param params An array of three parameters:
319316
* 1. address of the storage
320317
* 2. integer of the position in the storage
321318
* 3. integer block number, or the string "latest", "earliest" or "pending"
@@ -373,7 +370,7 @@ export class Eth {
373370

374371
/**
375372
* Returns the current ethereum protocol version as a hex-encoded string
376-
* @param {Array<*>} [params] An empty array
373+
* @param params An empty array
377374
*/
378375
protocolVersion(_params = []) {
379376
return `0x${this.ethVersion.toString(16)}`

packages/client/lib/rpc/modules/net.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { Chain } from '../../blockchain'
2-
import { EthereumService } from '../../service/ethereumservice'
31
import { middleware } from '../validation'
42
import { addHexPrefix } from 'ethereumjs-util'
5-
import { EthereumClient } from '../..'
6-
import { PeerPool } from '../../net/peerpool'
3+
import type { EthereumClient } from '../..'
4+
import type { Chain } from '../../blockchain'
5+
import type { PeerPool } from '../../net/peerpool'
6+
import type { EthereumService } from '../../service/ethereumservice'
77

88
/**
99
* net_* RPC module
1010
* @memberof module:rpc/modules
1111
*/
1212
export class Net {
1313
private _chain: Chain
14-
private _node: EthereumClient
14+
private _client: EthereumClient
1515
private _peerPool: PeerPool
1616

1717
/**
1818
* Create net_* RPC module
19-
* @param {Node} Node to which the module binds
19+
* @param client Client to which the module binds
2020
*/
21-
constructor(node: EthereumClient) {
22-
const service: EthereumService = node.services.find((s) => s.name === 'eth')!
21+
constructor(client: EthereumClient) {
22+
const service: EthereumService = client.services.find((s) => s.name === 'eth')!
2323
this._chain = service.chain
24-
this._node = node
24+
this._client = client
2525
this._peerPool = service.pool
2626

2727
this.version = middleware(this.version.bind(this), 0, [])
@@ -31,23 +31,23 @@ export class Net {
3131

3232
/**
3333
* Returns the current network id
34-
* @param {Array<*>} [params] An empty array
34+
* @param params An empty array
3535
*/
3636
version(_params = []) {
3737
return `${this._chain.config.chainCommon.chainId()}`
3838
}
3939

4040
/**
4141
* Returns true if client is actively listening for network connections
42-
* @param {Array<*>} [params] An empty array
42+
* @param params An empty array
4343
*/
4444
listening(_params = []) {
45-
return this._node.opened
45+
return this._client.opened
4646
}
4747

4848
/**
4949
* Returns number of peers currently connected to the client
50-
* @param {Array<*>} [params] An empty array
50+
* @param params An empty array
5151
*/
5252
peerCount(_params = []) {
5353
return addHexPrefix(this._peerPool.peers.length.toString(16))

packages/client/lib/rpc/modules/web3.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { middleware, validators } from '../validation'
21
import { addHexPrefix, keccak, toBuffer } from 'ethereumjs-util'
2+
import { middleware, validators } from '../validation'
33
import { getClientVersion } from '../../util'
4-
import { EthereumClient } from '../..'
5-
import { Chain } from '../../blockchain'
4+
import type { EthereumClient } from '../..'
5+
import type { Chain } from '../../blockchain'
6+
import type { EthereumService } from '../../service'
67

78
/**
89
* web3_* RPC module
@@ -13,11 +14,11 @@ export class Web3 {
1314

1415
/**
1516
* Create web3_* RPC module
16-
* @param {Node} Node to which the module binds
17+
* @param client Client to which the module binds
1718
*/
18-
constructor(node: EthereumClient) {
19-
const service = node.services.find((s) => s.name === 'eth')
20-
this._chain = service?.chain
19+
constructor(client: EthereumClient) {
20+
const service = client.services.find((s) => s.name === 'eth') as EthereumService
21+
this._chain = service.chain
2122

2223
this.clientVersion = middleware(this.clientVersion.bind(this), 0, [])
2324

@@ -26,15 +27,15 @@ export class Web3 {
2627

2728
/**
2829
* Returns the current client version
29-
* @param {Array<*>} [params] An empty array
30+
* @param params An empty array
3031
*/
3132
clientVersion(_params = []) {
3233
return getClientVersion()
3334
}
3435

3536
/**
3637
* Returns Keccak-256 (not the standardized SHA3-256) of the given data
37-
* @param {Array<string>} [params] The data to convert into a SHA3 hash
38+
* @param params The data to convert into a SHA3 hash
3839
*/
3940
sha3(params: string[]) {
4041
const rawDigest = keccak(toBuffer(params[0]))

packages/client/test/rpc/eth/call.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ tape(`${method}: call with valid arguments`, async (t) => {
1717
const service = client.services.find((s) => s.name === 'eth')
1818
const vm = (service!.synchronizer as FullSynchronizer).execution.vm
1919

20-
// since synchronizer.run() is not executed in the mock setup,
21-
// manually run stateManager.generateCanonicalGenesis()
22-
await vm.stateManager.generateCanonicalGenesis()
23-
2420
// genesis address with balance
2521
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
2622

packages/client/test/rpc/eth/estimateGas.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ tape(`${method}: call with valid arguments`, async (t) => {
1717
const service = client.services.find((s) => s.name === 'eth')
1818
const vm = (service!.synchronizer as FullSynchronizer).execution.vm
1919

20-
// since synchronizer.run() is not executed in the mock setup,
21-
// manually run stateManager.generateCanonicalGenesis()
22-
await vm.stateManager.generateCanonicalGenesis()
23-
2420
// genesis address with balance
2521
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
2622

packages/client/test/rpc/eth/getCode.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ tape(`${method}: ensure returns correct code`, async (t) => {
4040
const service = client.services.find((s) => s.name === 'eth')
4141
const vm = (service!.synchronizer as FullSynchronizer).execution.vm
4242

43-
// since synchronizer.run() is not executed in the mock setup,
44-
// manually run stateManager.generateCanonicalGenesis()
45-
await vm.stateManager.generateCanonicalGenesis()
46-
4743
// genesis address with balance
4844
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
4945

packages/client/test/rpc/eth/getStorageAt.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ const setup = async () => {
1717
const service = client.services.find((s) => s.name === 'eth')
1818
const vm = (service!.synchronizer as FullSynchronizer).execution.vm
1919

20-
// since synchronizer.run() is not executed in the mock setup,
21-
// manually run stateManager.generateCanonicalGenesis()
22-
await vm.stateManager.generateCanonicalGenesis()
23-
2420
// genesis address with balance
2521
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
2622

packages/client/test/rpc/eth/getTransactionCount.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tape(`${method}: call with valid arguments`, async (t) => {
1313
const manager = createManager(createClient({ blockchain, includeVM: true }))
1414
const server = startRPC(manager.getMethods())
1515

16-
// random genesis address
16+
// a genesis address
1717
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
1818

1919
// verify nonce is 0
@@ -39,7 +39,7 @@ tape(`${method}: ensure count increments after a tx`, async (t) => {
3939
const service = client.services.find((s) => s.name === 'eth')
4040
const vm = (service!.synchronizer as FullSynchronizer).execution.vm
4141

42-
// random genesis address with existing balance
42+
// a genesis address
4343
const address = Address.fromString('0xccfd725760a68823ff1e062f4cc97e1360e8d997')
4444

4545
// construct tx

0 commit comments

Comments
 (0)