mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 22:04:52 +00:00
simplify balance transfer
This commit is contained in:
parent
f1fac6be0f
commit
2f9f708f1b
@ -117,34 +117,16 @@ proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) =
|
|||||||
let senderBalance =
|
let senderBalance =
|
||||||
computation.vmState.readOnlyStateDb().
|
computation.vmState.readOnlyStateDb().
|
||||||
getBalance(computation.msg.sender)
|
getBalance(computation.msg.sender)
|
||||||
var newBalance = senderBalance
|
|
||||||
|
|
||||||
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}"
|
||||||
)
|
)
|
||||||
|
|
||||||
newBalance = senderBalance - computation.msg.value
|
|
||||||
computation.vmState.mutateStateDb:
|
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)
|
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:
|
else:
|
||||||
# even though the value is zero, the account
|
# even though the value is zero, the account
|
||||||
# should be exist.
|
# should be exist.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user