/
tipset.go
39 lines (31 loc) · 960 Bytes
/
tipset.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
package distributed
import (
"context"
"fmt"
"github.com/filecoin-project/lily/chain/indexer"
"github.com/filecoin-project/lotus/chain/types"
)
var _ indexer.Indexer = (*TipSetIndexer)(nil)
type Queue interface {
EnqueueTipSet(ctx context.Context, ts *types.TipSet, indexType indexer.IndexerType, tasks ...string) error
}
type TipSetIndexer struct {
q Queue
}
func NewTipSetIndexer(q Queue) *TipSetIndexer {
return &TipSetIndexer{q: q}
}
func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet, opts ...indexer.Option) (bool, error) {
o, err := indexer.ConstructOptions(opts...)
if err != nil {
return false, err
}
if o.IndexType == indexer.Undefined {
return false, fmt.Errorf("indexer type required")
}
log.Infow("index tipset", "height", ts.Height(), "type", o.IndexType.String(), "tasks", o.Tasks)
if err := t.q.EnqueueTipSet(ctx, ts, o.IndexType, o.Tasks...); err != nil {
return false, err
}
return true, nil
}