GraphQL: Move EVM-calling function makeCall to rpcMakeCall

`makeCall` used by GraphQL is another way to setup and call the EVM.
Move it to `transaction/call_evm`.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-03 09:07:56 +01:00
parent 8bda81496a
commit 6dd14e4f4f
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
2 changed files with 18 additions and 14 deletions

View File

@ -746,20 +746,11 @@ proc toCallData(n: Node): (RpcCallData, bool) =
(cd, gasLimit) (cd, gasLimit)
proc makeCall(ctx: GraphqlContextRef, callData: RpcCallData, header: BlockHeader, chainDB: BaseChainDB): RespResult = proc makeCall(ctx: GraphqlContextRef, callData: RpcCallData, header: BlockHeader, chainDB: BaseChainDB): RespResult =
# TODO: handle revert let (outputHex, gasUsed, isError) = rpcMakeCall(callData, header, chainDB)
var
# we use current header stateRoot, unlike block validation
# which use previous block stateRoot
vmState = newBaseVMState(header.stateRoot, header, chainDB)
fork = toFork(chainDB.config, header.blockNumber)
comp = rpcSetupComputation(vmState, callData, fork)
let gas = comp.gasMeter.gasRemaining
comp.execComputation()
var map = respMap(ctx.ids[ethCallResult]) var map = respMap(ctx.ids[ethCallResult])
map["data"] = resp("0x" & comp.output.toHex) map["data"] = resp("0x" & outputHex)
map["gasUsed"] = longNode(gas - comp.gasMeter.gasRemaining).get() map["gasUsed"] = longNode(gasUsed).get()
map["status"] = longNode(if comp.isError: 0 else: 1).get() map["status"] = longNode(if isError: 0 else: 1).get()
ok(map) ok(map)
proc blockCall(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} = proc blockCall(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =

View File

@ -7,7 +7,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
eth/common/eth_types, stint, options, eth/common/eth_types, stint, options, stew/byteutils,
".."/[vm_types, vm_types2, vm_state, vm_computation], ".."/[vm_types, vm_types2, vm_state, vm_computation],
".."/[db/db_chain, config, vm_state_transactions, rpc/hexstrings], ".."/[db/db_chain, config, vm_state_transactions, rpc/hexstrings],
".."/[db/accounts_cache, p2p/executor], eth/trie/db ".."/[db/accounts_cache, p2p/executor], eth/trie/db
@ -55,6 +55,19 @@ proc rpcDoCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): Hex
comp.execComputation() comp.execComputation()
result = hexDataStr(comp.output) result = hexDataStr(comp.output)
proc rpcMakeCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): (string, GasInt, bool) =
# TODO: handle revert
var
# we use current header stateRoot, unlike block validation
# which use previous block stateRoot
vmState = newBaseVMState(header.stateRoot, header, chain)
fork = toFork(chain.config, header.blockNumber)
comp = rpcSetupComputation(vmState, call, fork)
let gas = comp.gasMeter.gasRemaining
comp.execComputation()
return (comp.output.toHex, gas - comp.gasMeter.gasRemaining, comp.isError)
proc rpcEstimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): GasInt = proc rpcEstimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): GasInt =
# TODO: handle revert and error # TODO: handle revert and error
var var