Skip to content

Commit

Permalink
txapp: record correct spends in txapp (and cometbft)
Browse files Browse the repository at this point in the history
  • Loading branch information
charithabandi authored and jchappelow committed May 20, 2024
1 parent 04a2cfa commit 6822b3f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/txapp/txapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ func (r *TxApp) checkAndSpend(ctx TxContext, tx *transactions.Transaction, price
return nil, transactions.CodeUnknownError, err2
}

return nil, transactions.CodeInsufficientBalance, fmt.Errorf("transaction tries to spend %s tokens, but account only has %s tokens", amt.String(), tx.Body.Fee.String())
return account.Balance, transactions.CodeInsufficientBalance, fmt.Errorf("transaction tries to spend %s tokens, but account only has %s tokens", amt.String(), tx.Body.Fee.String())
}
if err != nil {
if errors.Is(err, accounts.ErrAccountNotFound) {
Expand All @@ -951,7 +951,7 @@ func (r *TxApp) checkAndSpend(ctx TxContext, tx *transactions.Transaction, price
return nil, transactions.CodeUnknownError, err
}

return nil, transactions.CodeInsufficientFee, fmt.Errorf("transaction does not consent to spending enough tokens. transaction fee: %s, required fee: %s", tx.Body.Fee.String(), amt.String())
return tx.Body.Fee, transactions.CodeInsufficientFee, fmt.Errorf("transaction does not consent to spending enough tokens. transaction fee: %s, required fee: %s", tx.Body.Fee.String(), amt.String())
}

// spend the tokens
Expand All @@ -967,7 +967,7 @@ func (r *TxApp) checkAndSpend(ctx TxContext, tx *transactions.Transaction, price
if err2 != nil {
return nil, transactions.CodeUnknownError, err2
}
return nil, transactions.CodeInsufficientBalance, fmt.Errorf("transaction tries to spend %s tokens, but account has %s tokens", amt.String(), account.Balance.String())
return account.Balance, transactions.CodeInsufficientBalance, fmt.Errorf("transaction tries to spend %s tokens, but account has %s tokens", amt.String(), account.Balance.String())
}
if err != nil {
if errors.Is(err, accounts.ErrAccountNotFound) { // probably wouldn't have passed the fee check
Expand Down

0 comments on commit 6822b3f

Please sign in to comment.