-
Notifications
You must be signed in to change notification settings - Fork 12
/
commands.go
199 lines (165 loc) · 5.63 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
192
193
194
195
196
197
198
199
/*
This work is licensed and released under GNU GPL v3 or any other later versions.
The full text of the license is below/ found at <http://www.gnu.org/licenses/>
(c) 2023 Rocket Pool Pty Ltd. Modified under GNU GPL v3. [1.5.0]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package wallet
import (
"github.com/urfave/cli"
"github.com/stader-labs/stader-node/shared/utils/api"
cliutils "github.com/stader-labs/stader-node/shared/utils/cli"
)
// Register subcommands
func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
command.Subcommands = append(command.Subcommands, cli.Command{
Name: name,
Aliases: aliases,
Usage: "Manage the node wallet",
Subcommands: []cli.Command{
{
Name: "status",
Aliases: []string{"s"},
Usage: "Get the node wallet status",
UsageText: "stader-cli api wallet status",
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(getStatus(c))
return nil
},
},
{
Name: "set-password",
Aliases: []string{"p"},
Usage: "Set the node wallet password",
UsageText: "stader-cli api wallet set-password password",
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
}
password, err := cliutils.ValidateNodePassword("wallet password", c.Args().Get(0))
if err != nil {
return err
}
// Run
api.PrintResponse(setPassword(c, password))
return nil
},
},
{
Name: "recover",
Aliases: []string{"r"},
Usage: "Recover a node wallet from a mnemonic phrase",
UsageText: "stader-cli api wallet recover mnemonic",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "skip-validator-key-recovery, k",
Usage: "Recover the node wallet, but do not regenerate its validator keys",
},
cli.StringFlag{
Name: "derivation-path, d",
Usage: "Specify the derivation path for the wallet.\nOmit this flag (or leave it blank) for the default of \"m/44'/60'/0'/0/%d\" (where %d is the index).\nSet this to \"ledgerLive\" to use Ledger Live's path of \"m/44'/60'/%d/0/0\".\nSet this to \"mew\" to use MyEtherWallet's path of \"m/44'/60'/0'/%d\".\nFor custom paths, simply enter them here.",
},
cli.UintFlag{
Name: "wallet-index, i",
Usage: "Specify the index to use with the derivation path when recovering your wallet",
Value: 0,
},
},
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
}
mnemonic, err := cliutils.ValidateWalletMnemonic("mnemonic", c.Args().Get(0))
if err != nil {
return err
}
// Run
api.PrintResponse(recoverWallet(c, mnemonic))
return nil
},
},
{
Name: "rebuild-validator-keys",
Aliases: []string{"rvk"},
Usage: "Rebuild a node wallet validator keys",
UsageText: "stader-cli api wallet rebuild-validator-keys",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(rebuildValidatorKeys(c))
return nil
},
},
{
Name: "init",
Aliases: []string{"i"},
Usage: "Initialize the node wallet",
UsageText: "stader-cli api wallet init",
Flags: []cli.Flag{
cli.StringFlag{
Name: "derivation-path, d",
Usage: "Specify the derivation path for the wallet.\nOmit this flag (or leave it blank) for the default of \"m/44'/60'/0'/0/%d\" (where %d is the index).\nSet this to \"ledgerLive\" to use Ledger Live's path of \"m/44'/60'/%d/0/0\".\nSet this to \"mew\" to use MyEtherWallet's path of \"m/44'/60'/0'/%d\".\nFor custom paths, simply enter them here.",
},
},
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(initWallet(c))
return nil
},
},
{
Name: "export",
Aliases: []string{"e"},
Usage: "Export the node wallet in JSON format",
UsageText: "stader-cli api wallet export",
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(exportWallet(c))
return nil
},
},
{
Name: "purge",
Usage: "Deletes your node wallet, your validator keys, and restarts your Validator Client while preserving your chain data. WARNING: Only use this if you want to stop validating with this machine!",
UsageText: "stader-cli api wallet purge",
Action: func(c *cli.Context) error {
// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(purge(c))
return nil
},
},
},
})
}