-
Notifications
You must be signed in to change notification settings - Fork 176
/
builder.go
67 lines (58 loc) · 1.48 KB
/
builder.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
61
62
63
64
65
66
67
package factories
import (
"github.com/dgraph-io/badger/v2"
"github.com/onflow/flow-go/module"
builder "github.com/onflow/flow-go/module/builder/collection"
finalizer "github.com/onflow/flow-go/module/finalizer/collection"
"github.com/onflow/flow-go/module/mempool"
"github.com/onflow/flow-go/network"
"github.com/onflow/flow-go/storage"
)
type BuilderFactory struct {
db *badger.DB
mainChainHeaders storage.Headers
trace module.Tracer
opts []builder.Opt
metrics module.CollectionMetrics
pusher network.Engine // engine for pushing finalized collection to consensus committee
}
func NewBuilderFactory(
db *badger.DB,
mainChainHeaders storage.Headers,
trace module.Tracer,
metrics module.CollectionMetrics,
pusher network.Engine,
opts ...builder.Opt,
) (*BuilderFactory, error) {
factory := &BuilderFactory{
db: db,
mainChainHeaders: mainChainHeaders,
trace: trace,
metrics: metrics,
pusher: pusher,
opts: opts,
}
return factory, nil
}
func (f *BuilderFactory) Create(
clusterHeaders storage.Headers,
clusterPayloads storage.ClusterPayloads,
pool mempool.Transactions,
) (module.Builder, *finalizer.Finalizer, error) {
build := builder.NewBuilder(
f.db,
f.trace,
f.mainChainHeaders,
clusterHeaders,
clusterPayloads,
pool,
f.opts...,
)
final := finalizer.NewFinalizer(
f.db,
pool,
f.pusher,
f.metrics,
)
return build, final, nil
}