Skip to content

Commit

Permalink
Core: fix available balance check
Browse files Browse the repository at this point in the history
  • Loading branch information
orogvany committed Jan 17, 2019
1 parent 14a97ec commit 454f0f9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/semux/core/TransactionExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ public List<TransactionResult> execute(List<Transaction> txs, AccountState as, D
case CALL:
case CREATE:
long maxGasFee = tx.getGas() * tx.getGasPrice();
Amount maxCost = sum(value, Unit.NANO_SEM.of(maxGasFee));
if (available.equals(maxCost)) {

Amount maxCost = sum(sum(value, fee), Unit.NANO_SEM.of(maxGasFee));

if (available.lt(maxCost)) {
result.setCode(Code.INSUFFICIENT_AVAILABLE);
break;
}

// VM calls can still take values
as.adjustAvailable(from, neg(value));
// VM calls can have fees/values set.
as.adjustAvailable(from, neg(sum(value, fee)));

if (tx.getGas() > config.vmMaxBlockGasLimit()) {
result.setCode(Code.INVALID_GAS);
Expand Down

0 comments on commit 454f0f9

Please sign in to comment.