waddrmgr/db: return ErrBlockNotFound if block doesn't exist
This commit is contained in:
parent
33629dcfc2
commit
61a2a8c391
2 changed files with 9 additions and 0 deletions
|
@ -8,6 +8,7 @@ package waddrmgr
|
|||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
@ -1876,6 +1877,10 @@ func fetchBlockHash(ns walletdb.ReadBucket, height int32) (*chainhash.Hash, erro
|
|||
heightBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(heightBytes, uint32(height))
|
||||
hashBytes := bucket.Get(heightBytes)
|
||||
if hashBytes == nil {
|
||||
err := errors.New("block not found")
|
||||
return nil, managerError(ErrBlockNotFound, errStr, err)
|
||||
}
|
||||
if len(hashBytes) != 32 {
|
||||
err := fmt.Errorf("couldn't get hash from database")
|
||||
return nil, managerError(ErrDatabase, errStr, err)
|
||||
|
|
|
@ -135,6 +135,10 @@ const (
|
|||
// ErrBirthdayBlockNotSet is returned when we attempt to retrieve the
|
||||
// wallet's birthday but it has not been set yet.
|
||||
ErrBirthdayBlockNotSet
|
||||
|
||||
// ErrBlockNotFound is returned when we attempt to retrieve the hash for
|
||||
// a block that we do not know of.
|
||||
ErrBlockNotFound
|
||||
)
|
||||
|
||||
// Map of ErrorCode values back to their constant names for pretty printing.
|
||||
|
|
Loading…
Reference in a new issue