Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative balances #1047

Merged
merged 2 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified lib/modAvmVersion1.jar
Binary file not shown.
Binary file modified lib/modAvmVersion2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public BigInteger getBalance(AionAddress address) {
*/
@Override
public void addBalance(AionAddress address, BigInteger amount) {
if (!this.isLocalCall && getBalance(address).add(amount).signum() < 0) {
throw new IllegalArgumentException("This balance adjustment leads to a negative balance!");
}
this.repository.addBalance(address, amount);
}

Expand Down Expand Up @@ -255,6 +258,9 @@ public boolean accountBalanceIsAtLeast(AionAddress address, BigInteger amount) {
@Override
public void deductEnergyCost(AionAddress address, BigInteger energyCost) {
if (!this.isLocalCall) {
if (getBalance(address).subtract(energyCost).signum() < 0) {
throw new IllegalArgumentException("This balance adjustment leads to a negative balance!");
}
this.repository.addBalance(address, energyCost.negate());
}
}
Expand Down