simplify balance transfer

This commit is contained in:
andri lim 2019-03-13 21:34:53 +07:00
parent f1fac6be0f
commit 2f9f708f1b
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 1 additions and 19 deletions

View File

@ -117,34 +117,16 @@ proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) =
let senderBalance =
computation.vmState.readOnlyStateDb().
getBalance(computation.msg.sender)
var newBalance = senderBalance
if senderBalance < computation.msg.value:
raise newException(InsufficientFunds,
&"Insufficient funds: {senderBalance} < {computation.msg.value}"
)
newBalance = senderBalance - computation.msg.value
computation.vmState.mutateStateDb:
db.setBalance(computation.msg.sender, newBalance)
db.subBalance(computation.msg.sender, computation.msg.value)
db.addBalance(computation.msg.storageAddress, computation.msg.value)
trace "Value transferred",
source = computation.msg.sender,
dest = computation.msg.storageAddress,
value = computation.msg.value,
oldSenderBalance = senderBalance,
newSenderBalance = newBalance,
gasPrice = computation.msg.gasPrice,
gas = computation.msg.gas
trace "Apply message",
value = computation.msg.value,
senderBalance = newBalance,
sender = computation.msg.sender.toHex,
address = computation.msg.storageAddress.toHex,
gasPrice = computation.msg.gasPrice,
gas = computation.msg.gas
else:
# even though the value is zero, the account
# should be exist.