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.} =
|
proc dispose*(snapshot: var ComputationSnapshot) {.inline.} =
|
||||||
snapshot.snapshot.dispose()
|
snapshot.snapshot.dispose()
|
||||||
|
|
||||||
proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) =
|
proc transferBalance(computation: var BaseComputation, opCode: static[Op]) =
|
||||||
if computation.msg.depth >= MaxCallDepth:
|
if computation.msg.depth >= MaxCallDepth:
|
||||||
raise newException(StackDepthError, "Stack depth limit reached")
|
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)
|
getBalance(computation.msg.sender)
|
||||||
|
|
||||||
if senderBalance < computation.msg.value:
|
if senderBalance < computation.msg.value:
|
||||||
raise newException(InsufficientFunds,
|
raise newException(InsufficientFunds,
|
||||||
&"Insufficient funds: {senderBalance} < {computation.msg.value}"
|
&"Insufficient funds: {senderBalance} < {computation.msg.value}")
|
||||||
)
|
|
||||||
|
|
||||||
computation.vmState.mutateStateDb:
|
computation.vmState.mutateStateDb:
|
||||||
db.subBalance(computation.msg.sender, computation.msg.value)
|
db.subBalance(computation.msg.sender, computation.msg.value)
|
||||||
db.addBalance(computation.msg.storageAddress, 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 =
|
proc applyMessage(computation: var BaseComputation, opCode: static[Op]): bool =
|
||||||
var snapshot = computation.snapshot()
|
var snapshot = computation.snapshot()
|
||||||
defer: snapshot.dispose()
|
defer: snapshot.dispose()
|
||||||
|
|
||||||
when opCode in {Call, Create}:
|
when opCode in {Call, Create}:
|
||||||
try:
|
try:
|
||||||
computation.applyMessageAux(opCode)
|
computation.transferBalance(opCode)
|
||||||
except VMError:
|
except VMError:
|
||||||
snapshot.revert()
|
snapshot.revert()
|
||||||
debug "applyMessageAux failed", msg = computation.error.info
|
debug "transferBalance failed", msg = computation.error.info
|
||||||
return
|
return
|
||||||
|
|
||||||
if computation.gasMeter.gasRemaining < 0:
|
if computation.gasMeter.gasRemaining < 0:
|
||||||
|
|
Loading…
Reference in New Issue