/
module.go
82 lines (74 loc) · 2.68 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
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
package modules
import (
"os"
"github.com/c-bata/go-prompt"
"github.com/make-os/kit/config"
"github.com/make-os/kit/extensions"
"github.com/make-os/kit/keystore"
"github.com/make-os/kit/mempool"
modulestypes "github.com/make-os/kit/modules/types"
dht2 "github.com/make-os/kit/net/dht"
"github.com/make-os/kit/node/services"
types3 "github.com/make-os/kit/rpc/types"
types2 "github.com/make-os/kit/ticket/types"
"github.com/make-os/kit/types/core"
"github.com/robertkrimen/otto"
)
// Module implements ModulesHub. It is a hub for other modules.
type Module struct {
cfg *config.AppConfig
attachMode bool
Modules *modulestypes.Modules
}
// New creates an instance of Module
func New(cfg *config.AppConfig, acctmgr *keystore.Keystore, service services.Service, logic core.Logic,
mempoolReactor *mempool.Reactor, ticketmgr types2.TicketManager, dht dht2.DHT,
extMgr *extensions.Manager, remoteSvr core.RemoteServer) *Module {
return &Module{
cfg: cfg,
Modules: &modulestypes.Modules{
Tx: NewTxModule(service, logic),
Chain: NewChainModule(service, logic),
User: NewUserModule(cfg, acctmgr, service, logic),
PushKey: NewPushKeyModule(cfg, service, logic),
Ticket: NewTicketModule(service, logic, ticketmgr),
Repo: NewRepoModule(service, remoteSvr, logic),
NS: NewNamespaceModule(service, remoteSvr, logic),
DHT: NewDHTModule(cfg, dht),
ExtMgr: extMgr,
Util: NewConsoleUtilModule(os.Stdout),
RPC: NewRPCModule(cfg),
Pool: NewPoolModule(mempoolReactor, remoteSvr.GetPushPool()),
Dev: NewDevModule(),
},
}
}
// NewAttachable creates an instance of Module configured for attach mode.
func NewAttachable(cfg *config.AppConfig, client types3.Client, ks *keystore.Keystore) *Module {
return &Module{
cfg: cfg,
attachMode: cfg.IsAttachMode(),
Modules: &modulestypes.Modules{
Tx: NewAttachableTxModule(client),
Chain: NewAttachableChainModule(client),
User: NewAttachableUserModule(cfg, client, ks),
PushKey: NewAttachablePushKeyModule(cfg, client),
Ticket: NewAttachableTicketModule(client),
Repo: NewAttachableRepoModule(client),
NS: NewAttachableNamespaceModule(client),
DHT: NewAttachableDHTModule(cfg, client),
Util: NewConsoleUtilModule(os.Stdout),
RPC: NewRPCModule(cfg),
Pool: NewAttachablePoolModule(client),
Dev: NewDevModule(),
},
}
}
// GetModules returns all sub-modules
func (m *Module) GetModules() *modulestypes.Modules {
return m.Modules
}
// ConfigureVM instructs VM-accessible modules accessible to configure the VM
func (m *Module) ConfigureVM(vm *otto.Otto) (sugs []prompt.Completer) {
return m.Modules.ConfigureVM(vm)
}