forked from ethereumjs/ethereumjs-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxpool.ts
48 lines (43 loc) · 1.39 KB
/
txpool.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { callWithStackTrace, toJSONRPCTx } from '../helpers.js'
import { middleware } from '../validation.js'
import type { EthereumClient } from '../../index.js'
import type { FullEthereumService } from '../../service/index.js'
import type { TxPool as Pool } from '../../service/txpool.js'
import type { VM } from '@ethereumjs/vm'
/**
* web3_* RPC module
* @memberof module:rpc/modules
*/
export class TxPool {
private _txpool: Pool
private _vm: VM
private _rpcDebug: boolean
/**
* Create web3_* RPC module
* @param client Client to which the module binds
*/
constructor(client: EthereumClient, rpcDebug: boolean) {
const service = client.service as FullEthereumService
this._txpool = service.txPool
this._vm = service.execution.vm
this._rpcDebug = rpcDebug
this.content = middleware(callWithStackTrace(this.content.bind(this), this._rpcDebug), 0, [])
}
/**
* Returns the contents of the transaction pool
* @param params An empty array
*/
content(_params = []) {
const pending = new Map()
for (const pool of this._txpool.pool) {
const pendingForAcct = new Map<bigint, any>()
for (const tx of pool[1]) {
pendingForAcct.set(tx.tx.nonce, toJSONRPCTx(tx.tx))
}
if (pendingForAcct.size > 0) pending.set('0x' + pool[0], Object.fromEntries(pendingForAcct))
}
return {
pending: Object.fromEntries(pending),
}
}
}