-
Notifications
You must be signed in to change notification settings - Fork 38
/
servicelocator.go
66 lines (53 loc) · 1.93 KB
/
servicelocator.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
package host
import (
"github.com/ethereum/go-ethereum/log"
hostcommon "github.com/ten-protocol/go-ten/go/common/host"
"github.com/ten-protocol/go-ten/go/host/l1"
)
type ServicesRegistry struct {
services map[string]hostcommon.Service
logger log.Logger
}
func NewServicesRegistry(logger log.Logger) *ServicesRegistry {
return &ServicesRegistry{
services: make(map[string]hostcommon.Service),
logger: logger,
}
}
func (s *ServicesRegistry) All() map[string]hostcommon.Service {
return s.services
}
func (s *ServicesRegistry) RegisterService(name string, service hostcommon.Service) {
if _, ok := s.services[name]; ok {
s.logger.Crit("service already registered", "name", name)
}
s.services[name] = service
}
func (s *ServicesRegistry) getService(name string) hostcommon.Service {
service, ok := s.services[name]
if !ok {
s.logger.Crit("requested service not registered", "name", name)
}
return service
}
func (s *ServicesRegistry) P2P() hostcommon.P2P {
return s.getService(hostcommon.P2PName).(hostcommon.P2P)
}
func (s *ServicesRegistry) L1Data() hostcommon.L1DataService {
return s.getService(hostcommon.L1DataServiceName).(hostcommon.L1DataService)
}
func (s *ServicesRegistry) L1Publisher() hostcommon.L1Publisher {
return s.getService(hostcommon.L1PublisherName).(hostcommon.L1Publisher)
}
func (s *ServicesRegistry) L2Repo() hostcommon.L2BatchRepository {
return s.getService(hostcommon.L2BatchRepositoryName).(hostcommon.L2BatchRepository)
}
func (s *ServicesRegistry) Enclaves() hostcommon.EnclaveService {
return s.getService(hostcommon.EnclaveServiceName).(hostcommon.EnclaveService)
}
func (s *ServicesRegistry) LogSubs() hostcommon.LogSubscriptionManager {
return s.getService(hostcommon.LogSubscriptionServiceName).(hostcommon.LogSubscriptionManager)
}
func (s *ServicesRegistry) CrossChainMachine() l1.CrossChainStateMachine {
return s.getService(hostcommon.CrossChainServiceName).(l1.CrossChainStateMachine)
}