From 61a2a8c39169face3b071b84ac51c7c8d1aa84c1 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 5 Nov 2018 17:06:33 -0800 Subject: [PATCH] waddrmgr/db: return ErrBlockNotFound if block doesn't exist --- waddrmgr/db.go | 5 +++++ waddrmgr/error.go | 4 ++++ 2 files changed, 9 insertions(+) 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.