Transaction: Change tx validation to use shared setupComputation

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-17 10:36:34 +01:00
parent 45da426bb8
commit 0d3117344a
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2

View File

@ -212,26 +212,17 @@ proc rpcEstimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB,
proc txSetupComputation(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork: Fork): Computation = proc txSetupComputation(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork: Fork): Computation =
var gas = tx.gasLimit - tx.intrinsicGas(fork) var gas = tx.gasLimit - tx.intrinsicGas(fork)
assert gas >= 0 assert gas >= 0
return setupComputation(CallParams(
vmState.setupTxContext( vmState: vmState,
origin = sender, forkOverride: some(fork),
gasPrice = tx.gasPrice, gasPrice: tx.gasPrice,
forkOverride = some(fork) gasLimit: gas,
)
let msg = Message(
kind: if tx.isContractCreation: evmcCreate else: evmcCall,
depth: 0,
gas: gas,
sender: sender, sender: sender,
contractAddress: tx.to, to: tx.to,
codeAddress: tx.to, isCreate: tx.isContractCreation,
value: tx.value, value: tx.value,
data: tx.payload input: tx.payload
) ))
result = newComputation(vmState, msg)
doAssert result.isOriginComputation
proc txRefundgas(tx: Transaction, sender: EthAddress, c: Computation) = proc txRefundgas(tx: Transaction, sender: EthAddress, c: Computation) =
let maxRefund = (tx.gasLimit - c.gasMeter.gasRemaining) div 2 let maxRefund = (tx.gasLimit - c.gasMeter.gasRemaining) div 2