/
bootstrapper.go
102 lines (83 loc) · 3.12 KB
/
bootstrapper.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package entity
import (
"github.com/centrifuge/centrifuge-protobufs/documenttypes"
"github.com/centrifuge/go-centrifuge/anchors"
"github.com/centrifuge/go-centrifuge/bootstrap"
"github.com/centrifuge/go-centrifuge/config"
"github.com/centrifuge/go-centrifuge/documents"
"github.com/centrifuge/go-centrifuge/documents/entityrelationship"
"github.com/centrifuge/go-centrifuge/errors"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/jobs"
"github.com/centrifuge/go-centrifuge/queue"
)
const (
// BootstrappedEntityHandler maps to grpc handler for entities
BootstrappedEntityHandler string = "BootstrappedEntityHandler"
// BootstrappedEntityService maps to the service for entities
BootstrappedEntityService string = "BootstrappedEntityService"
)
// Bootstrapper implements bootstrap.Bootstrapper.
type Bootstrapper struct{}
// Bootstrap sets the required storage and registers
func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error {
registry, ok := ctx[documents.BootstrappedRegistry].(*documents.ServiceRegistry)
if !ok {
return errors.New("service registry not initialised")
}
docSrv, ok := ctx[documents.BootstrappedDocumentService].(documents.Service)
if !ok {
return errors.New("document service not initialised")
}
repo, ok := ctx[documents.BootstrappedDocumentRepository].(documents.Repository)
if !ok {
return errors.New("document db repository not initialised")
}
repo.Register(&Entity{})
queueSrv, ok := ctx[bootstrap.BootstrappedQueueServer].(*queue.Server)
if !ok {
return errors.New("queue server not initialised")
}
jobManager, ok := ctx[jobs.BootstrappedService].(jobs.Manager)
if !ok {
return errors.New("transaction service not initialised")
}
cfgSrv, ok := ctx[config.BootstrappedConfigStorage].(config.Service)
if !ok {
return errors.New("config service not initialised")
}
factory, ok := ctx[identity.BootstrappedDIDFactory].(identity.Factory)
if !ok {
return errors.New("identity factory not initialised")
}
erService, ok := ctx[entityrelationship.BootstrappedEntityRelationshipService].(entityrelationship.Service)
if !ok {
return errors.New("entity relation service not initialised")
}
processor, ok := ctx[documents.BootstrappedAnchorProcessor].(documents.DocumentRequestProcessor)
if !ok {
return errors.New("processor not initialised")
}
anchorRepo, ok := ctx[anchors.BootstrappedAnchorRepo].(anchors.AnchorRepository)
if !ok {
return errors.New("anchor repository not initialised")
}
didService, ok := ctx[identity.BootstrappedDIDService].(identity.ServiceDID)
if !ok {
return errors.New("identity service not initialized")
}
// register service
srv := DefaultService(
docSrv,
repo,
queueSrv, jobManager, factory, erService, didService, anchorRepo, processor, func() documents.ValidatorGroup {
return documents.PostAnchoredValidator(didService, anchorRepo)
})
err := registry.Register(documenttypes.EntityDataTypeUrl, srv)
if err != nil {
return errors.New("failed to register entity service: %v", err)
}
ctx[BootstrappedEntityService] = srv
ctx[BootstrappedEntityHandler] = GRPCHandler(cfgSrv, srv)
return nil
}