From 1f120ee7b00c32dee0f710886870c23ae92a34a7 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Wed, 3 Jul 2024 12:10:28 -0400 Subject: [PATCH] fix too many variables error in updateBalance --- persist/sqlite/consensus.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index a5744547..88a329d0 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -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 {