simplify transferBalance again
This commit is contained in:
parent
2f9f708f1b
commit
44688259f1
|
@ -109,40 +109,31 @@ proc commit*(snapshot: var ComputationSnapshot) {.inline.} =
|
|||
proc dispose*(snapshot: var ComputationSnapshot) {.inline.} =
|
||||
snapshot.snapshot.dispose()
|
||||
|
||||
proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) =
|
||||
proc transferBalance(computation: var BaseComputation, opCode: static[Op]) =
|
||||
if computation.msg.depth >= MaxCallDepth:
|
||||
raise newException(StackDepthError, "Stack depth limit reached")
|
||||
|
||||
if computation.msg.value != 0:
|
||||
let senderBalance =
|
||||
computation.vmState.readOnlyStateDb().
|
||||
let senderBalance = computation.vmState.readOnlyStateDb().
|
||||
getBalance(computation.msg.sender)
|
||||
|
||||
if senderBalance < computation.msg.value:
|
||||
raise newException(InsufficientFunds,
|
||||
&"Insufficient funds: {senderBalance} < {computation.msg.value}"
|
||||
)
|
||||
&"Insufficient funds: {senderBalance} < {computation.msg.value}")
|
||||
|
||||
computation.vmState.mutateStateDb:
|
||||
db.subBalance(computation.msg.sender, computation.msg.value)
|
||||
db.addBalance(computation.msg.storageAddress, computation.msg.value)
|
||||
|
||||
else:
|
||||
# even though the value is zero, the account
|
||||
# should be exist.
|
||||
computation.vmState.mutateStateDb:
|
||||
db.addBalance(computation.msg.storageAddress, computation.msg.value)
|
||||
|
||||
proc applyMessage(computation: var BaseComputation, opCode: static[Op]): bool =
|
||||
var snapshot = computation.snapshot()
|
||||
defer: snapshot.dispose()
|
||||
|
||||
when opCode in {Call, Create}:
|
||||
try:
|
||||
computation.applyMessageAux(opCode)
|
||||
computation.transferBalance(opCode)
|
||||
except VMError:
|
||||
snapshot.revert()
|
||||
debug "applyMessageAux failed", msg = computation.error.info
|
||||
debug "transferBalance failed", msg = computation.error.info
|
||||
return
|
||||
|
||||
if computation.gasMeter.gasRemaining < 0:
|
||||
|
|
Loading…
Reference in New Issue