Skip to content

Commit

Permalink
Merge pull request #214 from Taraxa-project/negative_balance
Browse files Browse the repository at this point in the history
hotfix: dont store negative balance
  • Loading branch information
rattrap authored Nov 12, 2024
2 parents 57dce96 + 164745a commit 1e35be3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/storage/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Taraxa-project/taraxa-indexer/internal/common"
"github.com/Taraxa-project/taraxa-indexer/internal/events"
"github.com/Taraxa-project/taraxa-indexer/models"
log "github.com/sirupsen/logrus"
)

type Account struct {
Expand Down Expand Up @@ -74,6 +75,10 @@ func (a *Accounts) AddToBalance(address string, value *big.Int) {
if account.Balance.Cmp(big.NewInt(0)) == 0 {
a.RemoveBalance(address)
}
if account.Balance.Cmp(big.NewInt(0)) == -1 {
log.WithField("address", address).WithField("balance", account.Balance.String()).Error("Account balance is negative")
account.Balance = big.NewInt(0)
}
}

func (a *Accounts) UpdateBalances(from, to, value_str string) {
Expand Down

0 comments on commit 1e35be3

Please sign in to comment.