-
Notifications
You must be signed in to change notification settings - Fork 39
/
bootstrapper.go
60 lines (49 loc) · 1.82 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
package purchaseorder
import (
"errors"
"fmt"
"github.com/centrifuge/centrifuge-protobufs/documenttypes"
"github.com/centrifuge/go-centrifuge/anchors"
"github.com/centrifuge/go-centrifuge/config"
"github.com/centrifuge/go-centrifuge/coredocument"
"github.com/centrifuge/go-centrifuge/documents"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/p2p"
)
// Bootstrapper implements bootstrap.Bootstrapper.
type Bootstrapper struct{}
// Bootstrap initialises required services for purchaseorder.
func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error {
if _, ok := ctx[config.BootstrappedConfig]; !ok {
return errors.New("config hasn't been initialized")
}
cfg := ctx[config.BootstrappedConfig].(config.Configuration)
p2pClient, ok := ctx[p2p.BootstrappedP2PClient].(p2p.Client)
if !ok {
return fmt.Errorf("p2p client not initialised")
}
registry, ok := ctx[documents.BootstrappedRegistry].(*documents.ServiceRegistry)
if !ok {
return fmt.Errorf("service registry not initialised")
}
anchorRepo, ok := ctx[anchors.BootstrappedAnchorRepo].(anchors.AnchorRepository)
if !ok {
return fmt.Errorf("anchor repository not initialised")
}
idService, ok := ctx[identity.BootstrappedIDService].(identity.Service)
if !ok {
return fmt.Errorf("identity service not initialised")
}
repo, ok := ctx[documents.BootstrappedDocumentRepository].(documents.Repository)
if !ok {
return fmt.Errorf("document db repository not initialised")
}
repo.Register(&PurchaseOrder{})
// register service
srv := DefaultService(cfg, repo, coredocument.DefaultProcessor(idService, p2pClient, anchorRepo, cfg), anchorRepo, idService)
err := registry.Register(documenttypes.PurchaseOrderDataTypeUrl, srv)
if err != nil {
return fmt.Errorf("failed to register purchase order service")
}
return nil
}