Skip to content

Commit

Permalink
sqlite: fix siacoin element arg order
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 10, 2024
1 parent 0a750d7 commit bad3a93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func applySiacoinOutputs(tx txn, added map[types.Hash256]types.SiacoinElement) e
}

// insert the created utxo
_, err = addStmt.Exec(encode(se.ID), addressID, sqlCurrency(se.SiacoinOutput.Value), encodeSlice(se.MerkleProof), se.MaturityHeight, se.LeafIndex)
_, err = addStmt.Exec(encode(se.ID), addressID, sqlCurrency(se.SiacoinOutput.Value), encodeSlice(se.MerkleProof), se.LeafIndex, se.MaturityHeight)
if err != nil {
return fmt.Errorf("failed to insert output %q: %w", se.ID, err)
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func updateElementProofs(tx txn, table string, updater proofUpdater) error {
}
defer stmt.Close()

updateStmt, err := tx.Prepare(`UPDATE ` + table + ` SET merkle_proof=$1, leaf_index=$2 WHERE id=$3`)
updateStmt, err := tx.Prepare(`UPDATE ` + table + ` SET merkle_proof=$1, leaf_index=$2 WHERE id=$3 RETURNING id`)
if err != nil {
return fmt.Errorf("failed to prepare update statement: %w", err)
}
Expand Down Expand Up @@ -298,7 +298,8 @@ func updateElementProofs(tx txn, table string, updater proofUpdater) error {
}

for _, se := range updated {
_, err := updateStmt.Exec(encodeSlice(se.MerkleProof), se.LeafIndex, encode(se.ID))
var dummy types.Hash256
err := updateStmt.QueryRow(encodeSlice(se.MerkleProof), se.LeafIndex, encode(se.ID)).Scan(decode(&dummy, 32))
if err != nil {
return fmt.Errorf("failed to update siacoin element %q: %w", se.ID, err)
}
Expand All @@ -308,7 +309,6 @@ func updateElementProofs(tx txn, table string, updater proofUpdater) error {
break
}
}

return nil
}

Expand Down
9 changes: 3 additions & 6 deletions persist/sqlite/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ func (s *Store) UnspentSiacoinOutputs(walletID string) (siacoins []types.Siacoin

for rows.Next() {
var siacoin types.SiacoinElement
var proof []byte

err := rows.Scan(decode(&siacoin.ID, 32), &siacoin.LeafIndex, &proof, (*sqlCurrency)(&siacoin.SiacoinOutput.Value), decode(&siacoin.SiacoinOutput.Address, 32), &siacoin.MaturityHeight)
err := rows.Scan(decode(&siacoin.ID, 32), &siacoin.LeafIndex, decodeSlice[types.Hash256](&siacoin.MerkleProof, 32*1000), (*sqlCurrency)(&siacoin.SiacoinOutput.Value), decode(&siacoin.SiacoinOutput.Address, 32), &siacoin.MaturityHeight)
if err != nil {
return fmt.Errorf("failed to scan siacoin element: %w", err)
}

siacoins = append(siacoins, siacoin)
}
return nil
Expand All @@ -219,9 +218,7 @@ func (s *Store) UnspentSiafundOutputs(walletID string) (siafunds []types.Siafund

for rows.Next() {
var siafund types.SiafundElement
var proof []byte

err := rows.Scan(decode(&siafund.ID, 32), &siafund.LeafIndex, &proof, &siafund.SiafundOutput.Value, (*sqlCurrency)(&siafund.ClaimStart), decode(&siafund.SiafundOutput.Address, 32))
err := rows.Scan(decode(&siafund.ID, 32), &siafund.LeafIndex, decodeSlice(&siafund.MerkleProof, 32*1000), &siafund.SiafundOutput.Value, (*sqlCurrency)(&siafund.ClaimStart), decode(&siafund.SiafundOutput.Address, 32))
if err != nil {
return fmt.Errorf("failed to scan siacoin element: %w", err)
}
Expand Down

0 comments on commit bad3a93

Please sign in to comment.