GasMeter is an object now (#73)

This commit is contained in:
Yuriy Glukhov 2018-07-18 15:18:17 +03:00 committed by Mamy Ratsimbazafy
parent 6c67115ef5
commit b2acf3a5e3
5 changed files with 12 additions and 11 deletions

View File

@ -18,7 +18,7 @@ proc newBaseComputation*(vmState: BaseVMState, blockNumber: UInt256, message: Me
result.msg = message
result.memory = Memory()
result.stack = newStack()
result.gasMeter = newGasMeter(message.gas)
result.gasMeter.init(message.gas)
result.children = @[]
result.accountsToDelete = initTable[EthAddress, EthAddress]()
result.logEntries = @[]

View File

@ -9,12 +9,11 @@ import
strformat, eth_common, # GasInt
../../logging, ../../errors, ../../vm_types
proc newGasMeter*(startGas: GasInt): GasMeter =
new(result)
result.startGas = startGas
result.gasRemaining = result.startGas
result.gasRefunded = 0
result.logger = logging.getLogger("gas")
proc init*(m: var GasMeter, startGas: GasInt) =
m.startGas = startGas
m.gasRemaining = m.startGas
m.gasRefunded = 0
m.logger = logging.getLogger("gas")
proc consumeGas*(gasMeter: var GasMeter; amount: GasInt; reason: string) =
#if amount < 0.u256:

View File

@ -565,7 +565,7 @@ op create, inline = false, value, startPosition, size:
# let childComputation = applyChildBaseComputation(computation, childMsg)
var childComputation: BaseComputation # TODO - stub
new childComputation
childComputation.gasMeter = newGasMeter(0) # TODO GasMeter should be a normal object.
childComputation.gasMeter.init(0)
if childComputation.isError:
push: 0
@ -739,7 +739,7 @@ template genCall(callName: untyped): untyped =
# let childComputation = applyChildBaseComputation(computation, childMsg)
var childComputation: BaseComputation # TODO - stub
new childComputation
childComputation.gasMeter = newGasMeter(0) # TODO GasMeter should be a normal object.
childComputation.gasMeter.init(0)
if childComputation.isError:
push: 0

View File

@ -45,7 +45,7 @@ type
kind*: Op
runLogic*: proc(computation: var BaseComputation)
GasMeter* = ref object # TODO: use a normal object
GasMeter* = object
logger*: Logger
gasRefunded*: GasInt
startGas*: GasInt

View File

@ -15,8 +15,10 @@ import
# disableLogging()
proc initGasMeter(startGas: GasInt): GasMeter = result.init(startGas)
proc gasMeters: seq[GasMeter] =
@[newGasMeter(10), newGasMeter(100), newGasMeter(999)]
@[initGasMeter(10), initGasMeter(100), initGasMeter(999)]
macro all(element: untyped, handler: untyped): untyped =
let name = ident(&"{element.repr}s")