-
Notifications
You must be signed in to change notification settings - Fork 7
/
commands.go
191 lines (156 loc) · 5 KB
/
commands.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package vega
import (
"log"
"code.vegaprotocol.io/vegacapsule/config"
"code.vegaprotocol.io/vegacapsule/types"
"code.vegaprotocol.io/vegacapsule/utils"
)
type initateNodeOutput struct {
ConfigFilePath string `json:"configFilePath"`
NodeWalletConfigFilePath string `json:"nodeWalletConfigFilePath"`
}
type generateNodeWalletOutput struct {
Mnemonic string `json:"mnemonic,omitempty"`
RegistryFilePath string `json:"registryFilePath"`
WalletFilePath string `json:"walletFilePath"`
}
type importNodeWalletOutput struct {
RegistryFilePath string `json:"registryFilePath"`
TendermintPubkey string `json:"tendermintPubkey"`
WalletFilePath string `json:"walletFilePath"`
}
type createWalletOutput struct {
Wallet struct {
Name string `json:"name"`
FilePath string `json:"filePath"`
RecoveryPhrase string `json:"recoveryPhrase"`
} `json:"wallet"`
Key struct {
Public string `json:"publicKey"`
} `json:"key"`
}
type describeWalletOutput struct {
Name string `json:"name"`
ID string `json:"id"`
}
func (vg ConfigGenerator) initiateNode(binaryPath, homePath string, nodeWalletPhraseFile string, nodeMode string) (*initateNodeOutput, error) {
args := []string{
"init",
"--home", homePath,
"--nodewallet-passphrase-file", nodeWalletPhraseFile,
"--no-tendermint",
"--output", "json",
string(nodeMode),
}
log.Printf("Initiating node %q with: %s %v", nodeMode, binaryPath, args)
out := &initateNodeOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, out); err != nil {
return nil, err
}
return out, nil
}
func (vg ConfigGenerator) createWallet(binaryPath, homePath, name, walletPhraseFilePath string) (*createWalletOutput, error) {
args := []string{
config.WalletSubCmd,
"--home", homePath,
"create",
"--output", "json",
"--passphrase-file", walletPhraseFilePath,
"--wallet", name,
}
log.Printf("Creating vega wallet with: %s %v", binaryPath, args)
out := &createWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, out); err != nil {
return nil, err
}
return out, nil
}
func (vg ConfigGenerator) describeWallet(binaryPath, homePath, name, walletPhraseFilePath string) (*describeWalletOutput, error) {
args := []string{
config.WalletSubCmd,
"--home", homePath,
"describe",
"--output", "json",
"--passphrase-file", walletPhraseFilePath,
"--wallet", name,
}
log.Printf("Collecting vega node id with: %s %v", binaryPath, args)
out := &describeWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, out); err != nil {
return nil, err
}
return out, nil
}
func (vg ConfigGenerator) generateNodeWallet(binaryPath, homePath string, nodeWalletPhraseFile string, walletPhraseFile string, walletType string) (*generateNodeWalletOutput, error) {
args := []string{
"nodewallet",
"--home", homePath,
"--passphrase-file", nodeWalletPhraseFile,
"generate",
"--output", "json",
"--chain", walletType,
"--wallet-passphrase-file", walletPhraseFile,
}
log.Printf("Generating node %q wallet with: %s %v", walletType, binaryPath, args)
out := &generateNodeWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, out); err != nil {
return nil, err
}
return out, nil
}
func (vg ConfigGenerator) importEthereumClefNodeWallet(
binaryPath, homePath, nodeWalletPhraseFile string,
clefAccountAddr, clefRPCAddr string,
) (*importNodeWalletOutput, error) {
args := []string{
"nodewallet",
"--home", homePath,
"--passphrase-file", nodeWalletPhraseFile,
"import",
"--output", "json",
"--chain", "ethereum",
"--ethereum-clef-account", clefAccountAddr,
"--ethereum-clef-address", clefRPCAddr,
}
log.Printf("Importing Ethereum Clef wallet: %v", args)
nwo := &importNodeWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, nwo); err != nil {
return nil, err
}
return nwo, nil
}
func (vg ConfigGenerator) importTendermintNodeWallet(binaryPath, homePath string, nodeWalletPhraseFile string, tendermintHomePath string) (*importNodeWalletOutput, error) {
args := []string{
"nodewallet",
"--home", homePath,
"--passphrase-file", nodeWalletPhraseFile,
"import",
"--output", "json",
"--chain", "tendermint",
"--tendermint-home", tendermintHomePath,
}
log.Printf("Importing tenderming wallet: %v", args)
nwo := &importNodeWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, nwo); err != nil {
return nil, err
}
return nwo, nil
}
func (vg ConfigGenerator) importVegaNodeWallet(binaryPath, homePath, nodeWalletPhraseFile, walletPhraseFile, walletFilePath string) (*importNodeWalletOutput, error) {
args := []string{
"nodewallet",
"--home", homePath,
"--passphrase-file", nodeWalletPhraseFile,
"import",
"--output", "json",
"--chain", types.NodeWalletChainTypeVega,
"--wallet-passphrase-file", walletPhraseFile,
"--wallet-path", walletFilePath,
}
log.Printf("Importing node vega wallet with: %s %v", binaryPath, args)
out := &importNodeWalletOutput{}
if _, err := utils.ExecuteBinary(binaryPath, args, out); err != nil {
return nil, err
}
return out, nil
}