From c3676ccc7bee3fb3b6bef492dd0616d82c422449 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Fri, 11 Oct 2024 20:12:25 -0400 Subject: [PATCH] fix search issue --- explorer/explorer.go | 2 +- persist/sqlite/blocks.go | 2 +- persist/sqlite/consensus.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/explorer/explorer.go b/explorer/explorer.go index 7eff3b80..292eaca5 100644 --- a/explorer/explorer.go +++ b/explorer/explorer.go @@ -289,7 +289,7 @@ func (e *Explorer) Search(id types.Hash256) (SearchType, error) { } _, err = e.Block(types.BlockID(id)) - if err != nil && err != sql.ErrNoRows { + if err != nil && !errors.Is(err, sql.ErrNoRows) { return SearchTypeInvalid, err } else if err == nil { return SearchTypeBlock, nil diff --git a/persist/sqlite/blocks.go b/persist/sqlite/blocks.go index 028c0653..15ece33b 100644 --- a/persist/sqlite/blocks.go +++ b/persist/sqlite/blocks.go @@ -12,7 +12,7 @@ func (s *Store) Block(id types.BlockID) (result explorer.Block, err error) { err = s.transaction(func(tx *txn) error { var v2Height uint64 var v2Commitment types.Hash256 - err := tx.QueryRow(`SELECT parent_id, nonce, timestamp, height, v2_height, v2_commitment FROM blocks WHERE id=?`, encode(id)).Scan(decode(&result.ParentID), decode(&result.Nonce), decode(&result.Timestamp), &result.Height, decodeNull(&v2Height), decodeNull(&v2Commitment)) + err := tx.QueryRow(`SELECT parent_id, nonce, timestamp, height, v2_height, v2_commitment FROM blocks WHERE id = ?`, encode(id)).Scan(decode(&result.ParentID), decode(&result.Nonce), decode(&result.Timestamp), &result.Height, decodeNull(&v2Height), decodeNull(&v2Commitment)) if err != nil { return fmt.Errorf("failed to get block: %w", err) } diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index 57443275..fd4d463d 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -18,13 +18,13 @@ type updateTx struct { func addBlock(tx *txn, b types.Block, height uint64) error { // nonce is encoded because database/sql doesn't support uint64 with high bit set - var v2Height uint64 - var v2Commitment types.Hash256 + var v2Height any + var v2Commitment any if b.V2 != nil { - v2Height = b.V2.Height - v2Commitment = b.V2.Commitment + v2Height = encode(b.V2.Height) + v2Commitment = encode(b.V2.Commitment) } - _, err := tx.Exec("INSERT INTO blocks(id, height, parent_id, nonce, timestamp, v2_height, v2_commitment) VALUES (?, ?, ?, ?, ?, ?, ?);", encode(b.ID()), height, encode(b.ParentID), encode(b.Nonce), encode(b.Timestamp), v2Height, encode(v2Commitment)) + _, err := tx.Exec("INSERT INTO blocks(id, height, parent_id, nonce, timestamp, v2_height, v2_commitment) VALUES (?, ?, ?, ?, ?, ?, ?);", encode(b.ID()), height, encode(b.ParentID), encode(b.Nonce), encode(b.Timestamp), v2Height, v2Commitment) return err }