-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
116 lines (97 loc) · 2.4 KB
/
client.go
File metadata and controls
116 lines (97 loc) · 2.4 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package lumera
import (
"context"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/action"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/action_msg"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/auth"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/node"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/supernode"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/tx"
)
type lumeraClient struct {
cfg *Config
authMod auth.Module
actionMod action.Module
actionMsgMod action_msg.Module
supernodeMod supernode.Module
txMod tx.Module
nodeMod node.Module
conn Connection
}
func newClient(ctx context.Context, cfg *Config) (Client, error) {
conn, err := newGRPCConnection(ctx, cfg.GRPCAddr)
if err != nil {
return nil, err
}
txModule, err := tx.NewModule(conn.GetConn())
if err != nil {
conn.Close()
return nil, err
}
authModule, err := auth.NewModule(conn.GetConn())
if err != nil {
conn.Close()
return nil, err
}
actionModule, err := action.NewModule(conn.GetConn())
if err != nil {
conn.Close()
return nil, err
}
supernodeModule, err := supernode.NewModule(conn.GetConn())
if err != nil {
conn.Close()
return nil, err
}
nodeModule, err := node.NewModule(conn.GetConn(), cfg.keyring)
if err != nil {
conn.Close()
return nil, err
}
actionMsgModule, err := action_msg.NewModule(
conn.GetConn(),
authModule, // For account info
txModule, // For transaction operations
cfg.keyring, // For signing
cfg.KeyName, // Key to use
cfg.ChainID, // Chain configuration
)
if err != nil {
conn.Close()
return nil, err
}
return &lumeraClient{
cfg: cfg,
authMod: authModule,
actionMod: actionModule,
actionMsgMod: actionMsgModule,
supernodeMod: supernodeModule,
txMod: txModule,
nodeMod: nodeModule,
conn: conn,
}, nil
}
func (c *lumeraClient) Auth() auth.Module {
return c.authMod
}
func (c *lumeraClient) Action() action.Module {
return c.actionMod
}
func (c *lumeraClient) ActionMsg() action_msg.Module {
return c.actionMsgMod
}
func (c *lumeraClient) SuperNode() supernode.Module {
return c.supernodeMod
}
func (c *lumeraClient) Tx() tx.Module {
return c.txMod
}
func (c *lumeraClient) Node() node.Module {
return c.nodeMod
}
func (c *lumeraClient) Close() error {
if c.conn != nil {
return c.conn.Close()
}
return nil
}