-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetcher.go
More file actions
45 lines (36 loc) · 935 Bytes
/
fetcher.go
File metadata and controls
45 lines (36 loc) · 935 Bytes
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
package dasmon
import (
"context"
"io"
)
type Fetcher interface {
io.Closer
// FetchCommitments retrieves the BlockCommitmentInfos for a range of slots.
FetchCommitments(context.Context, Range[uint64]) ([]*BlockCommitmentInfo, error)
// MaxSlotsPerFetch specifies the maximum number of slots that can be fetched in a single call.
MaxSlotsPerFetch() uint64
}
var _ Fetcher = ChainedFetcher{}
type ChainedFetcher []Fetcher
func (cf ChainedFetcher) Close() error {
for _, f := range cf {
f.Close()
}
return nil
}
func (cf ChainedFetcher) MaxSlotsPerFetch() uint64 {
return cf[0].MaxSlotsPerFetch()
}
func (cf ChainedFetcher) FetchCommitments(ctx context.Context, r Range[uint64]) ([]*BlockCommitmentInfo, error) {
var finalErr error
for _, f := range cf {
infos, err := f.FetchCommitments(ctx, r)
if err == nil {
return infos, nil
}
if finalErr == nil {
finalErr = err
}
}
return nil, finalErr
}