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

Fix: negative balances #702

Merged
merged 1 commit into from
Jun 21, 2021
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
10 changes: 6 additions & 4 deletions internal/models/tokenbalance/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func (tb *TokenBalance) MarshalToQueue() ([]byte, error) {
// LogFields -
func (tb *TokenBalance) LogFields() logrus.Fields {
return logrus.Fields{
"network": tb.Network.String(),
"address": tb.Address,
"contract": tb.Contract,
"token_id": tb.TokenID,
"network": tb.Network.String(),
"address": tb.Address,
"contract": tb.Contract,
"token_id": tb.TokenID,
"balance": tb.Balance.String(),
"is_ledger": tb.IsLedger,
}
}
20 changes: 12 additions & 8 deletions internal/parsers/operations/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (p Transaction) Parse(data noderpc.Operation) (*parsers.Result, error) {
return nil, err
}
}

if !tezerrors.HasParametersError(tx.Errors) {
if err := p.transferParser.Parse(tx.BigMapDiffs, p.head.Protocol, &tx); err != nil {
if !errors.Is(err, noderpc.InvalidNodeResponse{}) {
Expand All @@ -102,6 +103,17 @@ func (p Transaction) Parse(data noderpc.Operation) (*parsers.Result, error) {
}
result.TokenBalances = append(result.TokenBalances, transferParsers.UpdateTokenBalances(tx.Transfers)...)
}

if tx.IsApplied() {
ledgerResult, err := ledger.New(p.ctx.TokenBalances).Parse(&tx, p.stackTrace)
if err != nil {
return nil, err
}
if ledgerResult != nil {
result.TokenBalances = append(result.TokenBalances, ledgerResult.TokenBalances...)
}
}

return result, nil
}

Expand Down Expand Up @@ -154,14 +166,6 @@ func (p Transaction) appliedHandler(item noderpc.Operation, tx *operation.Operat
result.Migrations = append(result.Migrations, migration)
}

ledgerResult, err := ledger.New(p.ctx.TokenBalances).Parse(tx, p.stackTrace)
if err != nil {
return err
}
if ledgerResult != nil {
result.TokenBalances = append(result.TokenBalances, ledgerResult.TokenBalances...)
}

return nil
}

Expand Down