Skip to content

Commit

Permalink
feat: prevent failed txn being calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
stinkymonkeyph committed Aug 6, 2024
1 parent 55d0620 commit 5d07ef7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions blockchain/walletIndex.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package blockchain

import "log"
import (
"log"

"github.com/stinkymonkeyph/gopher-blocks/constants"
)

type WalletTransactionIndex struct {
BlockHeight int `json:"block_height"`
Expand Down Expand Up @@ -38,9 +42,9 @@ func (w *WalletIndex) CalculateBalance(address string) int {
bal := 0

for _, txn := range w.Transactions[address] {
if txn.Transaction.From == address {
if txn.Transaction.From == address && txn.Transaction.Status == constants.STATUS_SUCCESS {
bal -= int(txn.Transaction.Value)
} else if txn.Transaction.To == address {
} else if txn.Transaction.To == address && txn.Transaction.Status == constants.STATUS_SUCCESS {
bal += int(txn.Transaction.Value)
}
}
Expand Down

0 comments on commit 5d07ef7

Please sign in to comment.