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 (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -1876,6 +1877,10 @@ func fetchBlockHash(ns walletdb.ReadBucket, height int32) (*chainhash.Hash, erro
|
||||||
heightBytes := make([]byte, 4)
|
heightBytes := make([]byte, 4)
|
||||||
binary.BigEndian.PutUint32(heightBytes, uint32(height))
|
binary.BigEndian.PutUint32(heightBytes, uint32(height))
|
||||||
hashBytes := bucket.Get(heightBytes)
|
hashBytes := bucket.Get(heightBytes)
|
||||||
|
if hashBytes == nil {
|
||||||
|
err := errors.New("block not found")
|
||||||
|
return nil, managerError(ErrBlockNotFound, errStr, err)
|
||||||
|
}
|
||||||
if len(hashBytes) != 32 {
|
if len(hashBytes) != 32 {
|
||||||
err := fmt.Errorf("couldn't get hash from database")
|
err := fmt.Errorf("couldn't get hash from database")
|
||||||
return nil, managerError(ErrDatabase, errStr, err)
|
return nil, managerError(ErrDatabase, errStr, err)
|
||||||
|
|
|
@ -135,6 +135,10 @@ const (
|
||||||
// ErrBirthdayBlockNotSet is returned when we attempt to retrieve the
|
// ErrBirthdayBlockNotSet is returned when we attempt to retrieve the
|
||||||
// wallet's birthday but it has not been set yet.
|
// wallet's birthday but it has not been set yet.
|
||||||
ErrBirthdayBlockNotSet
|
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.
|
// Map of ErrorCode values back to their constant names for pretty printing.
|
||||||
|
|
Loading…
Reference in a new issue