/
handle_stats.go
50 lines (40 loc) · 1.34 KB
/
handle_stats.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
// Copyright 2021 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
package chunksPkg
import (
"context"
"fmt"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/index"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk"
)
func (opts *ChunksOptions) HandleStats(blockNums []uint64) error {
chain := opts.Globals.Chain
ctx, cancel := context.WithCancel(context.Background())
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
showFinalizedStats := func(walker *walk.CacheWalker, path string, first bool) (bool, error) {
if path != index.ToBloomPath(path) {
return false, fmt.Errorf("should not happen in showFinalizedStats")
}
if s, err := GetChunkStats(chain, path); err != nil {
return false, err
} else {
modelChan <- &s
}
return true, nil
}
walker := walk.NewCacheWalker(
chain,
opts.Globals.TestMode,
100, /* maxTests */
showFinalizedStats,
)
if err := walker.WalkBloomFilters(blockNums); err != nil {
errorChan <- err
cancel()
}
}
return output.StreamMany(ctx, fetchData, opts.Globals.OutputOpts())
}