-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
60 lines (54 loc) · 1.78 KB
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package headerfs
import (
"github.com/kaotisk-hund/cjdcoind/btcutil/er"
"github.com/kaotisk-hund/cjdcoind/cjdcoinwallet/walletdb"
"github.com/kaotisk-hund/cjdcoind/chaincfg/chainhash"
"github.com/kaotisk-hund/cjdcoind/wire"
)
// ErrHeaderNotFound is returned when a target header on disk (flat file) can't
// be found.
var ErrHeaderNotFound = er.GenericErrorType.Code("headerfs.ErrHeaderNotFound")
// readHeaderRange will attempt to fetch a series of block headers within the
// target height range.
//
// NOTE: The end height is _inclusive_ so we'll fetch all headers from the
// startHeight up to the end height, including the final header.
func (h *blockHeaderStore) readHeaderRange(
tx walletdb.ReadTx,
startHeight uint32,
endHeight uint32,
) ([]wire.BlockHeader, er.R) {
out := make([]wire.BlockHeader, 0, endHeight-startHeight+1)
for i := startHeight; i <= endHeight; i++ {
if he, err := h.readHeader(tx, i); err != nil {
return nil, err
} else if hdr, err := blockHeaderFromHe(he); err != nil {
return nil, err
} else {
out = append(out, *hdr.BlockHeader)
}
}
return out, nil
}
// readHeaderRange will attempt to fetch a series of filter headers within the
// target height range.
//
// NOTE: The end height is _inclusive_ so we'll fetch all headers from the
// startHeight up to the end height, including the final header.
func (f *FilterHeaderStore) readHeaderRange(
tx walletdb.ReadTx,
startHeight uint32,
endHeight uint32,
) ([]chainhash.Hash, er.R) {
out := make([]chainhash.Hash, 0, endHeight-startHeight+1)
for i := startHeight; i <= endHeight; i++ {
if ret, err := f.readHeader(tx, i); err != nil {
return nil, err
} else if hash, err := chainhash.NewHash(ret.bytes); err != nil {
return nil, err
} else {
out = append(out, *hash)
}
}
return out, nil
}