@@ -11,14 +11,27 @@ import
11
11
json_rpc/ rpcserver,
12
12
chronicles,
13
13
web3/ [eth_api_types, conversions],
14
- ../ network/ state/ state_endpoints
14
+ ../ network/ state/ state_endpoints,
15
+ ../ evm/ [async_evm, async_evm_portal_backend]
15
16
16
17
template getOrRaise (stateNetwork: Opt [StateNetwork ]): StateNetwork =
17
18
let sn = stateNetwork.valueOr:
18
19
raise newException (ValueError , " state sub-network not enabled" )
19
20
sn
20
21
22
+ template getOrRaise (asyncEvm: Opt [AsyncEvm ]): AsyncEvm =
23
+ let evm = asyncEvm.valueOr:
24
+ raise
25
+ newException (ValueError , " portal evm requires state sub-network to be enabled" )
26
+ evm
27
+
21
28
proc installDebugApiHandlers * (rpcServer: RpcServer , stateNetwork: Opt [StateNetwork ]) =
29
+ let asyncEvm =
30
+ if stateNetwork.isSome ():
31
+ Opt .some (AsyncEvm .init (stateNetwork.get ().toAsyncEvmStateBackend ()))
32
+ else :
33
+ Opt .none (AsyncEvm )
34
+
22
35
rpcServer.rpc (" debug_getBalanceByStateRoot" ) do (
23
36
address: Address , stateRoot: Hash32
24
37
) -> UInt256 :
@@ -120,3 +133,37 @@ proc installDebugApiHandlers*(rpcServer: RpcServer, stateNetwork: Opt[StateNetwo
120
133
storageHash: proofs.account.storageRoot,
121
134
storageProof: storageProof,
122
135
)
136
+
137
+ rpcServer.rpc (" debug_callByStateRoot" ) do (
138
+ tx: TransactionArgs ,
139
+ stateRoot: Hash32 ,
140
+ quantityTag: Opt [RtBlockIdentifier ],
141
+ optimisticStateFetch: Opt [bool ]
142
+ ) -> seq [byte ]:
143
+ # TODO : add documentation
144
+
145
+ # This endpoint can be used to test eth_call without requiring the history network
146
+ # to be enabled. This is useful for scenarios where we don't yet have the block headers
147
+ # seeded into the history network.
148
+
149
+ if tx.to.isNone ():
150
+ raise newException (ValueError , " to address is required" )
151
+
152
+ let quantityTag = quantityTag.valueOr:
153
+ blockId (0 .uint64 )
154
+ if quantityTag.kind == bidAlias:
155
+ raise newException (ValueError , " tag not yet implemented" )
156
+
157
+ let
158
+ evm = asyncEvm.getOrRaise ()
159
+ header = Header (stateRoot: stateRoot, number: quantityTag.number.uint64 )
160
+ optimisticStateFetch = optimisticStateFetch.valueOr:
161
+ true
162
+
163
+ let callResult = (await evm.call (header, tx, optimisticStateFetch)).valueOr:
164
+ raise newException (ValueError , error)
165
+
166
+ if callResult.error.len () > 0 :
167
+ raise newException (ValueError , callResult.error)
168
+
169
+ callResult.output
0 commit comments