diff --git a/waddrmgr/db.go b/waddrmgr/db.go index 1765cd4..e9dd41d 100644 --- a/waddrmgr/db.go +++ b/waddrmgr/db.go @@ -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) diff --git a/waddrmgr/error.go b/waddrmgr/error.go index 0ff575c..bb3acc2 100644 --- a/waddrmgr/error.go +++ b/waddrmgr/error.go @@ -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.