mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
RPC: Move EVM-calling function doCall to rpcDoCall
`doCall` used by JSON-RPC 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:
parent
7c3b7ab7a8
commit
2732af99eb
@ -15,7 +15,8 @@ import
|
||||
../transaction, ../config, ../vm_state, ../constants, ../vm_types,
|
||||
../utils, ../db/[db_chain, state_db],
|
||||
rpc_types, rpc_utils, ../vm_message, ../vm_computation,
|
||||
../vm_types2
|
||||
../vm_types2,
|
||||
../transaction/call_evm
|
||||
|
||||
#[
|
||||
Note:
|
||||
@ -261,7 +262,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB , server: RpcServer) =
|
||||
let
|
||||
header = headerFromTag(chain, quantityTag)
|
||||
callData = callData(call, true, chain)
|
||||
result = doCall(callData, header, chain)
|
||||
result = rpcDoCall(callData, header, chain)
|
||||
|
||||
server.rpc("eth_estimateGas") do(call: EthCall, quantityTag: string) -> HexQuantityStr:
|
||||
## Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.
|
||||
|
@ -180,19 +180,6 @@ proc callData*(call: EthCall, callMode: bool = true, chain: BaseChainDB): RpcCal
|
||||
if call.data.isSome:
|
||||
result.data = hexToSeqByte(call.data.get.string)
|
||||
|
||||
proc doCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): HexDataStr =
|
||||
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)
|
||||
|
||||
comp.execComputation()
|
||||
result = hexDataStr(comp.output)
|
||||
# TODO: handle revert and error
|
||||
# TODO: handle contract ABI
|
||||
|
||||
proc estimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): GasInt =
|
||||
var
|
||||
# we use current header stateRoot, unlike block validation
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
import
|
||||
eth/common/eth_types, stint, options,
|
||||
".."/[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]
|
||||
|
||||
type
|
||||
RpcCallData* = object
|
||||
@ -39,3 +40,16 @@ proc rpcSetupComputation*(vmState: BaseVMState, call: RpcCallData, fork: Fork):
|
||||
)
|
||||
|
||||
return newComputation(vmState, msg)
|
||||
|
||||
proc rpcDoCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): HexDataStr =
|
||||
# TODO: handle revert and error
|
||||
# TODO: handle contract ABI
|
||||
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)
|
||||
|
||||
comp.execComputation()
|
||||
result = hexDataStr(comp.output)
|
||||
|
Loading…
x
Reference in New Issue
Block a user