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 too many variables error in updateBalance #50

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
24 changes: 9 additions & 15 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,26 +360,20 @@ func updateBalances(tx *txn, height uint64, spentSiacoinElements, newSiacoinElem
addresses[sfe.SiafundOutput.Address] = balance{}
}

var addressList []any
for address := range addresses {
addressList = append(addressList, encode(address))
}

rows, err := tx.Query(`SELECT address, siacoin_balance, immature_siacoin_balance, siafund_balance
FROM address_balance
WHERE address IN (`+queryPlaceHolders(len(addressList))+`)`, addressList...)
balanceRowsStmt, err := tx.Prepare(`SELECT siacoin_balance, immature_siacoin_balance, siafund_balance
FROM address_balance
WHERE address = ?`)
if err != nil {
return fmt.Errorf("updateBalances: failed to query address_balance: %w", err)
return fmt.Errorf("updateBalances: failed to prepare address_balance statement: %w", err)
}
defer rows.Close()
defer balanceRowsStmt.Close()

for rows.Next() {
for addr := range addresses {
var bal balance
var address types.Address
if err := rows.Scan(decode(&address), decode(&bal.sc), decode(&bal.immatureSC), decode(&bal.sf)); err != nil {
return err
if err := balanceRowsStmt.QueryRow(encode(addr)).Scan(decode(&bal.sc), decode(&bal.immatureSC), decode(&bal.sf)); err != sql.ErrNoRows && err != nil {
return fmt.Errorf("updateBalances: failed to scan balance: %w", err)
}
addresses[address] = bal
addresses[addr] = bal
}

for _, sce := range newSiacoinElements {
Expand Down
Loading