Update eth_estimateGas to use optional types

This commit is contained in:
coffeepots 2018-11-29 18:30:07 +00:00 committed by Ștefan Talpalaru
parent 3f1122702e
commit ab0f8f6748
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
1 changed files with 17 additions and 8 deletions

View File

@ -375,25 +375,34 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
## call: the transaction call object. ## call: the transaction call object.
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter. ## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
## Returns the amount of gas used. ## Returns the amount of gas used.
# TODO: Use optional fields with EthCall
var var
header = chain.headerFromTag(quantityTag) header = chain.headerFromTag(quantityTag)
vmState = newBaseVMState(header, chain) vmState = newBaseVMState(header, chain)
let let
gasLimit = if call.gas > 0.GasInt: call.gas else: header.gasLimit gasLimit = if
gasPrice = if call.gasPrice > 0: call.gasPrice else: 0.GasInt call.gas.isSome and call.gas.get > 0.GasInt: call.gas.get
else: header.gasLimit
gasPrice = if
call.gasPrice.isSome and call.gasPrice.get > 0: call.gasPrice.get
else: 0.GasInt
sender = if
call.source.isSome: call.source.get.toAddress
else: ZERO_ADDRESS
destination = if
call.to.isSome: call.to.get.toAddress
else: ZERO_ADDRESS
curState = chain.getStateDb(header.stateRoot, true) curState = chain.getStateDb(header.stateRoot, true)
sender = call.source.string.strToAddress
destination = call.to.string.strToAddress
nonce = curState.getNonce(sender) nonce = curState.getNonce(sender)
value = call.value value = if
# TODO: Use initTransaction when merged call.value.isSome: call.value.get
else: 0.u256
transaction = Transaction( transaction = Transaction(
accountNonce: nonce, accountNonce: nonce,
gasPrice: gasPrice, gasPrice: gasPrice,
gasLimit: gasLimit, gasLimit: gasLimit,
to: destination, to: destination,
value: value.u256, value: value,
payload: @[] payload: @[]
) )
result = vmState.binarySearchGas(transaction, sender, gasPrice) result = vmState.binarySearchGas(transaction, sender, gasPrice)