-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
49 lines (42 loc) · 1.16 KB
/
module.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
package state
import (
"context"
logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"
modfraud "github.com/furyaxyz/elysium-node/nodebuilder/fraud"
"github.com/furyaxyz/elysium-node/nodebuilder/node"
"github.com/furyaxyz/elysium-node/state"
)
var log = logging.Logger("module/state")
// ConstructModule provides all components necessary to construct the
// state service.
func ConstructModule(tp node.Type, cfg *Config) fx.Option {
// sanitize config values before constructing module
cfgErr := cfg.Validate()
baseComponents := fx.Options(
fx.Supply(*cfg),
fx.Error(cfgErr),
fx.Provide(fx.Annotate(
coreAccessor,
fx.OnStart(func(ctx context.Context, breaker *modfraud.ServiceBreaker[*state.CoreAccessor]) error {
return breaker.Start(ctx)
}),
fx.OnStop(func(ctx context.Context, breaker *modfraud.ServiceBreaker[*state.CoreAccessor]) error {
return breaker.Stop(ctx)
}),
)),
// the module is needed for the handler
fx.Provide(func(ca *state.CoreAccessor) Module {
return ca
}),
)
switch tp {
case node.Light, node.Full, node.Bridge:
return fx.Module(
"state",
baseComponents,
)
default:
panic("invalid node type")
}
}