Skip to content

Commit 1bb197e

Browse files
committed
format
1 parent 5077e27 commit 1bb197e

File tree

13 files changed

+216
-153
lines changed

13 files changed

+216
-153
lines changed

nimbus_verified_proxy/engine/accounts.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ proc populateCachesForAccountAndSlots(
213213
let
214214
proof =
215215
try:
216-
await engine.backend.eth_getProof(
217-
address, slotsToFetch, blockId(blockNumber)
218-
)
216+
await engine.backend.eth_getProof(address, slotsToFetch, blockId(blockNumber))
219217
except CatchableError as e:
220218
return err(e.msg)
221219
account = getAccountFromProof(

nimbus_verified_proxy/engine/engine.nim

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77

88
{.push raises: [], gcsafe.}
99

10-
import
11-
./types,
12-
./header_store,
13-
./utils,
14-
./rpc_frontend,
15-
./header_store,
16-
./evm
10+
import ./types, ./header_store, ./utils, ./rpc_frontend, ./header_store, ./evm
1711

1812
proc init*(
19-
T: type RpcVerificationEngine,
20-
config: RpcVerificationEngineConf
13+
T: type RpcVerificationEngine, config: RpcVerificationEngineConf
2114
): T {.raises: [ValueError].} =
2215
let engine = RpcVerificationEngine(
2316
chainId: config.chainId,

nimbus_verified_proxy/engine/fees.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func median(prices: var openArray[GasInt]): GasInt =
3434
# default case
3535
return GasInt(0)
3636

37-
proc suggestGasPrice*(engine: RpcVerificationEngine): Future[Result[GasInt, string]] {.async.} =
37+
proc suggestGasPrice*(
38+
engine: RpcVerificationEngine
39+
): Future[Result[GasInt, string]] {.async.} =
3840
const minGasPrice = 30_000_000_000.GasInt
3941
let
4042
blk = (await engine.getBlock(blockId("latest"), true)).valueOr:

nimbus_verified_proxy/engine/rpc_frontend.nim

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
3636

3737
latest.number.uint64
3838

39-
engine.frontend.eth_getBalance = proc(address: Address, quantityTag: BlockTag): Future[UInt256] {.async.} =
39+
engine.frontend.eth_getBalance = proc(
40+
address: Address, quantityTag: BlockTag
41+
): Future[UInt256] {.async.} =
4042
let
4143
header = (await engine.getHeader(quantityTag)).valueOr:
4244
raise newException(ValueError, error)
@@ -45,16 +47,22 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
4547

4648
account.balance
4749

48-
engine.frontend.eth_getStorageAt = proc(address: Address, slot: UInt256, quantityTag: BlockTag): Future[FixedBytes[32]] {.async.} =
50+
engine.frontend.eth_getStorageAt = proc(
51+
address: Address, slot: UInt256, quantityTag: BlockTag
52+
): Future[FixedBytes[32]] {.async.} =
4953
let
5054
header = (await engine.getHeader(quantityTag)).valueOr:
5155
raise newException(ValueError, error)
52-
storage = (await engine.getStorageAt(address, slot, header.number, header.stateRoot)).valueOr:
56+
storage = (
57+
await engine.getStorageAt(address, slot, header.number, header.stateRoot)
58+
).valueOr:
5359
raise newException(ValueError, error)
5460

5561
storage.to(Bytes32)
5662

57-
engine.frontend.eth_getTransactionCount = proc(address: Address, quantityTag: BlockTag): Future[Quantity] {.async.} =
63+
engine.frontend.eth_getTransactionCount = proc(
64+
address: Address, quantityTag: BlockTag
65+
): Future[Quantity] {.async.} =
5866
let
5967
header = (await engine.getHeader(quantityTag)).valueOr:
6068
raise newException(ValueError, error)
@@ -63,7 +71,9 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
6371

6472
Quantity(account.nonce)
6573

66-
engine.frontend.eth_getCode = proc(address: Address, quantityTag: BlockTag): Future[seq[byte]] {.async.} =
74+
engine.frontend.eth_getCode = proc(
75+
address: Address, quantityTag: BlockTag
76+
): Future[seq[byte]] {.async.} =
6777
let
6878
header = (await engine.getHeader(quantityTag)).valueOr:
6979
raise newException(ValueError, error)
@@ -72,39 +82,53 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
7282

7383
code
7484

75-
engine.frontend.eth_getBlockByHash = proc(blockHash: Hash32, fullTransactions: bool): Future[BlockObject] {.async.} =
85+
engine.frontend.eth_getBlockByHash = proc(
86+
blockHash: Hash32, fullTransactions: bool
87+
): Future[BlockObject] {.async.} =
7688
(await engine.getBlock(blockHash, fullTransactions)).valueOr:
7789
raise newException(ValueError, error)
7890

79-
engine.frontend.eth_getBlockByNumber = proc(blockTag: BlockTag, fullTransactions: bool): Future[BlockObject] {.async.} =
91+
engine.frontend.eth_getBlockByNumber = proc(
92+
blockTag: BlockTag, fullTransactions: bool
93+
): Future[BlockObject] {.async.} =
8094
(await engine.getBlock(blockTag, fullTransactions)).valueOr:
8195
raise newException(ValueError, error)
8296

83-
engine.frontend.eth_getUncleCountByBlockNumber = proc(blockTag: BlockTag): Future[Quantity] {.async.} =
97+
engine.frontend.eth_getUncleCountByBlockNumber = proc(
98+
blockTag: BlockTag
99+
): Future[Quantity] {.async.} =
84100
let blk = (await engine.getBlock(blockTag, false)).valueOr:
85101
raise newException(ValueError, error)
86102

87103
Quantity(blk.uncles.len())
88104

89-
engine.frontend.eth_getUncleCountByBlockHash = proc(blockHash: Hash32): Future[Quantity] {.async.} =
105+
engine.frontend.eth_getUncleCountByBlockHash = proc(
106+
blockHash: Hash32
107+
): Future[Quantity] {.async.} =
90108
let blk = (await engine.getBlock(blockHash, false)).valueOr:
91109
raise newException(ValueError, error)
92110

93111
Quantity(blk.uncles.len())
94112

95-
engine.frontend.eth_getBlockTransactionCountByNumber = proc(blockTag: BlockTag): Future[Quantity] {.async.} =
113+
engine.frontend.eth_getBlockTransactionCountByNumber = proc(
114+
blockTag: BlockTag
115+
): Future[Quantity] {.async.} =
96116
let blk = (await engine.getBlock(blockTag, true)).valueOr:
97117
raise newException(ValueError, error)
98118

99119
Quantity(blk.transactions.len)
100120

101-
engine.frontend.eth_getBlockTransactionCountByHash = proc(blockHash: Hash32): Future[Quantity] {.async.} =
121+
engine.frontend.eth_getBlockTransactionCountByHash = proc(
122+
blockHash: Hash32
123+
): Future[Quantity] {.async.} =
102124
let blk = (await engine.getBlock(blockHash, true)).valueOr:
103125
raise newException(ValueError, error)
104126

105127
Quantity(blk.transactions.len)
106128

107-
engine.frontend.eth_getTransactionByBlockNumberAndIndex = proc(blockTag: BlockTag, index: Quantity): Future[TransactionObject] {.async.} =
129+
engine.frontend.eth_getTransactionByBlockNumberAndIndex = proc(
130+
blockTag: BlockTag, index: Quantity
131+
): Future[TransactionObject] {.async.} =
108132
let blk = (await engine.getBlock(blockTag, true)).valueOr:
109133
raise newException(ValueError, error)
110134

@@ -116,7 +140,9 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
116140

117141
x.tx
118142

119-
engine.frontend.eth_getTransactionByBlockHashAndIndex = proc(blockHash: Hash32, index: Quantity): Future[TransactionObject] {.async.} =
143+
engine.frontend.eth_getTransactionByBlockHashAndIndex = proc(
144+
blockHash: Hash32, index: Quantity
145+
): Future[TransactionObject] {.async.} =
120146
let blk = (await engine.getBlock(blockHash, true)).valueOr:
121147
raise newException(ValueError, error)
122148

@@ -128,13 +154,14 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
128154

129155
x.tx
130156

131-
engine.frontend.eth_call = proc(tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true): Future[seq[byte]] {.async.} =
157+
engine.frontend.eth_call = proc(
158+
tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true
159+
): Future[seq[byte]] {.async.} =
132160
if tx.to.isNone():
133161
raise newException(ValueError, "to address is required")
134162

135-
let
136-
header = (await engine.getHeader(blockTag)).valueOr:
137-
raise newException(ValueError, error)
163+
let header = (await engine.getHeader(blockTag)).valueOr:
164+
raise newException(ValueError, error)
138165

139166
# Start fetching code to get it in the code cache
140167
discard engine.getCode(tx.to.get(), header.number, header.stateRoot)
@@ -157,13 +184,14 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
157184

158185
return callResult.output
159186

160-
engine.frontend.eth_createAccessList = proc(tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true): Future[AccessListResult] {.async.} =
187+
engine.frontend.eth_createAccessList = proc(
188+
tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true
189+
): Future[AccessListResult] {.async.} =
161190
if tx.to.isNone():
162191
raise newException(ValueError, "to address is required")
163192

164-
let
165-
header = (await engine.getHeader(blockTag)).valueOr:
166-
raise newException(ValueError, error)
193+
let header = (await engine.getHeader(blockTag)).valueOr:
194+
raise newException(ValueError, error)
167195

168196
# Start fetching code to get it in the code cache
169197
discard engine.getCode(tx.to.get(), header.number, header.stateRoot)
@@ -182,13 +210,14 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
182210
return
183211
AccessListResult(accessList: accessList, error: error, gasUsed: gasUsed.Quantity)
184212

185-
engine.frontend.eth_estimateGas = proc(tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true): Future[Quantity] {.async.} =
213+
engine.frontend.eth_estimateGas = proc(
214+
tx: TransactionArgs, blockTag: BlockTag, optimisticStateFetch: bool = true
215+
): Future[Quantity] {.async.} =
186216
if tx.to.isNone():
187217
raise newException(ValueError, "to address is required")
188218

189-
let
190-
header = (await engine.getHeader(blockTag)).valueOr:
191-
raise newException(ValueError, error)
219+
let header = (await engine.getHeader(blockTag)).valueOr:
220+
raise newException(ValueError, error)
192221

193222
# Start fetching code to get it in the code cache
194223
discard engine.getCode(tx.to.get(), header.number, header.stateRoot)
@@ -204,7 +233,9 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
204233

205234
return gasEstimate.Quantity
206235

207-
engine.frontend.eth_getTransactionByHash = proc(txHash: Hash32): Future[TransactionObject] {.async.} =
236+
engine.frontend.eth_getTransactionByHash = proc(
237+
txHash: Hash32
238+
): Future[TransactionObject] {.async.} =
208239
let tx =
209240
try:
210241
await engine.backend.eth_getTransactionByHash(txHash)
@@ -223,12 +254,16 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
223254

224255
return tx
225256

226-
engine.frontend.eth_getBlockReceipts = proc(blockTag: BlockTag): Future[Opt[seq[ReceiptObject]]] {.async.} =
257+
engine.frontend.eth_getBlockReceipts = proc(
258+
blockTag: BlockTag
259+
): Future[Opt[seq[ReceiptObject]]] {.async.} =
227260
let rxs = (await engine.getReceipts(blockTag)).valueOr:
228261
raise newException(ValueError, error)
229262
return Opt.some(rxs)
230263

231-
engine.frontend.eth_getTransactionReceipt = proc(txHash: Hash32): Future[ReceiptObject] {.async.} =
264+
engine.frontend.eth_getTransactionReceipt = proc(
265+
txHash: Hash32
266+
): Future[ReceiptObject] {.async.} =
232267
let
233268
rx =
234269
try:
@@ -244,11 +279,15 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
244279

245280
raise newException(ValueError, "receipt couldn't be verified")
246281

247-
engine.frontend.eth_getLogs = proc(filterOptions: FilterOptions): Future[seq[LogObject]] {.async.} =
282+
engine.frontend.eth_getLogs = proc(
283+
filterOptions: FilterOptions
284+
): Future[seq[LogObject]] {.async.} =
248285
(await engine.getLogs(filterOptions)).valueOr:
249286
raise newException(ValueError, error)
250287

251-
engine.frontend.eth_newFilter = proc(filterOptions: FilterOptions): Future[string] {.async.} =
288+
engine.frontend.eth_newFilter = proc(
289+
filterOptions: FilterOptions
290+
): Future[string] {.async.} =
252291
if engine.filterStore.len >= MAX_FILTERS:
253292
raise newException(ValueError, "FilterStore already full")
254293

@@ -283,14 +322,18 @@ proc registerDefaultFrontend*(engine: RpcVerificationEngine) =
283322

284323
return false
285324

286-
engine.frontend.eth_getFilterLogs = proc(filterId: string): Future[seq[LogObject]] {.async.} =
325+
engine.frontend.eth_getFilterLogs = proc(
326+
filterId: string
327+
): Future[seq[LogObject]] {.async.} =
287328
if filterId notin engine.filterStore:
288329
raise newException(ValueError, "Filter doesn't exist")
289330

290331
(await engine.getLogs(engine.filterStore[filterId].filter)).valueOr:
291332
raise newException(ValueError, error)
292333

293-
engine.frontend.eth_getFilterChanges = proc(filterId: string): Future[seq[LogObject]] {.async.} =
334+
engine.frontend.eth_getFilterChanges = proc(
335+
filterId: string
336+
): Future[seq[LogObject]] {.async.} =
294337
if filterId notin engine.filterStore:
295338
raise newException(ValueError, "Filter doesn't exist")
296339

nimbus_verified_proxy/engine/types.nim

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ type
4040

4141
# state methods
4242
GetBalanceProc* = proc(address: Address, blockId: BlockTag): Future[UInt256] {.async.}
43-
GetStorageProc* = proc(address: Address, slot: UInt256, blockId: BlockTag): Future[FixedBytes[32]] {.async.}
44-
GetTransactionCountProc* = proc(address: Address, blockId: BlockTag): Future[Quantity] {.async.}
43+
GetStorageProc* = proc(
44+
address: Address, slot: UInt256, blockId: BlockTag
45+
): Future[FixedBytes[32]] {.async.}
46+
GetTransactionCountProc* =
47+
proc(address: Address, blockId: BlockTag): Future[Quantity] {.async.}
4548
GetCodeProc* = proc(address: Address, blockId: BlockTag): Future[seq[byte]] {.async.}
46-
GetProofProc* = proc(address: Address, slots: seq[UInt256], blockId: BlockTag): Future[ProofResponse] {.async.}
49+
GetProofProc* = proc(
50+
address: Address, slots: seq[UInt256], blockId: BlockTag
51+
): Future[ProofResponse] {.async.}
4752

4853
# block methods
4954
GetBlockByHashProc* =
@@ -52,26 +57,36 @@ type
5257
proc(blkNum: BlockTag, fullTransactions: bool): Future[BlockObject] {.async.}
5358
GetUncleCountByBlockHashProc* = proc(blkHash: Hash32): Future[Quantity] {.async.}
5459
GetUncleCountByBlockNumberProc* = proc(blkNum: BlockTag): Future[Quantity] {.async.}
55-
GetBlockTransactionCountByHashProc* = proc(blkHash: Hash32): Future[Quantity] {.async.}
56-
GetBlockTransactionCountByNumberProc* = proc(blkNum: BlockTag): Future[Quantity] {.async.}
60+
GetBlockTransactionCountByHashProc* =
61+
proc(blkHash: Hash32): Future[Quantity] {.async.}
62+
GetBlockTransactionCountByNumberProc* =
63+
proc(blkNum: BlockTag): Future[Quantity] {.async.}
5764

5865
# transaction methods
59-
GetTransactionByBlockHashAndIndexProc* = proc(blkHash: Hash32, index: Quantity): Future[TransactionObject] {.async.}
60-
GetTransactionByBlockNumberAndIndexProc* = proc(blkNum: BlockTag, index: Quantity): Future[TransactionObject] {.async.}
66+
GetTransactionByBlockHashAndIndexProc* =
67+
proc(blkHash: Hash32, index: Quantity): Future[TransactionObject] {.async.}
68+
GetTransactionByBlockNumberAndIndexProc* =
69+
proc(blkNum: BlockTag, index: Quantity): Future[TransactionObject] {.async.}
6170
GetTransactionByHashProc = proc(txHash: Hash32): Future[TransactionObject] {.async.}
6271

6372
# evm method types for frontend with extra parameter
64-
FrontendCallProc* = proc(args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true): Future[seq[byte]] {.async.}
65-
FrontendCreateAccessListProc* =
66-
proc(args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true): Future[AccessListResult] {.async.}
67-
FrontendEstimateGasProc* = proc(args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true): Future[Quantity] {.async.}
73+
FrontendCallProc* = proc(
74+
args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true
75+
): Future[seq[byte]] {.async.}
76+
FrontendCreateAccessListProc* = proc(
77+
args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true
78+
): Future[AccessListResult] {.async.}
79+
FrontendEstimateGasProc* = proc(
80+
args: TransactionArgs, blockId: BlockTag, optimisticFetch: bool = true
81+
): Future[Quantity] {.async.}
6882

6983
# evm method types for backend (standard)
70-
CallProc* = proc(args: TransactionArgs, blockId: BlockTag): Future[seq[byte]] {.async.}
84+
CallProc* =
85+
proc(args: TransactionArgs, blockId: BlockTag): Future[seq[byte]] {.async.}
7186
CreateAccessListProc* =
7287
proc(args: TransactionArgs, blockId: BlockTag): Future[AccessListResult] {.async.}
73-
EstimateGasProc* = proc(args: TransactionArgs, blockId: BlockTag): Future[Quantity] {.async.}
74-
88+
EstimateGasProc* =
89+
proc(args: TransactionArgs, blockId: BlockTag): Future[Quantity] {.async.}
7590

7691
# receipt methods
7792
GetBlockReceiptsProc =
@@ -100,8 +115,7 @@ type
100115
eth_getTransactionByHash*: GetTransactionByHashProc
101116
eth_getLogs*: GetLogsProc
102117

103-
EthApiFrontend* = object
104-
# Chain methods
118+
EthApiFrontend* = object # Chain methods
105119
eth_chainId*: ChainIdProc
106120
eth_blockNumber*: BlockNumberProc
107121

0 commit comments

Comments
 (0)