modify estimateGas in rpc_utils.nim and it can be reusable for graphql too
This commit is contained in:
parent
82d4f6a2d4
commit
3dfc1501f0
|
@ -274,7 +274,8 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB , server: RpcServer) =
|
|||
let
|
||||
header = chain.headerFromTag(quantityTag)
|
||||
callData = callData(call, false, chain)
|
||||
result = estimateGas(callData, header, chain, call.gas.isSome)
|
||||
gasUsed = estimateGas(callData, header, chain, call.gas.isSome)
|
||||
result = encodeQuantity(gasUsed.uint64)
|
||||
|
||||
server.rpc("eth_getBlockByHash") do(data: EthHashStr, fullTransactions: bool) -> Option[BlockObject]:
|
||||
## Returns information about a block by hash.
|
||||
|
|
|
@ -24,13 +24,13 @@ type
|
|||
contractCreation* {.rlpIgnore.}: bool
|
||||
|
||||
CallData* = object
|
||||
source: EthAddress
|
||||
to: EthAddress
|
||||
gas: GasInt
|
||||
gasPrice: GasInt
|
||||
value: UInt256
|
||||
data: seq[byte]
|
||||
contractCreation: bool
|
||||
source*: EthAddress
|
||||
to*: EthAddress
|
||||
gas*: GasInt
|
||||
gasPrice*: GasInt
|
||||
value*: UInt256
|
||||
data*: seq[byte]
|
||||
contractCreation*: bool
|
||||
|
||||
proc read(rlp: var Rlp, t: var UnsignedTx, _: type EthAddress): EthAddress {.inline.} =
|
||||
if rlp.blobLen != 0:
|
||||
|
@ -188,7 +188,7 @@ proc callData*(call: EthCall, callMode: bool = true, chain: BaseChainDB): CallDa
|
|||
if call.data.isSome:
|
||||
result.data = hexToSeqByte(call.data.get.string)
|
||||
|
||||
proc setupComputation(vmState: BaseVMState, call: CallData, fork: Fork) : Computation =
|
||||
proc setupComputation*(vmState: BaseVMState, call: CallData, fork: Fork) : Computation =
|
||||
vmState.setupTxContext(
|
||||
origin = call.source,
|
||||
gasPrice = call.gasPrice,
|
||||
|
@ -221,7 +221,7 @@ proc doCall*(call: CallData, header: BlockHeader, chain: BaseChainDB): HexDataSt
|
|||
# TODO: handle revert and error
|
||||
# TODO: handle contract ABI
|
||||
|
||||
proc estimateGas*(call: CallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): HexQuantityStr =
|
||||
proc estimateGas*(call: CallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): GasInt =
|
||||
var
|
||||
# we use current header stateRoot, unlike block validation
|
||||
# which use previous block stateRoot
|
||||
|
@ -239,8 +239,7 @@ proc estimateGas*(call: CallData, header: BlockHeader, chain: BaseChainDB, haveG
|
|||
|
||||
var dbTx = chain.db.beginTransaction()
|
||||
defer: dbTx.dispose()
|
||||
let gasUsed = processTransaction(tx, call.source, vmState, fork)
|
||||
result = encodeQuantity(gasUsed.uint64)
|
||||
result = processTransaction(tx, call.source, vmState, fork)
|
||||
dbTx.dispose()
|
||||
# TODO: handle revert and error
|
||||
|
||||
|
|
Loading…
Reference in New Issue