Skip to content

Commit 2b6145b

Browse files
committed
Remove cli dep from wallet commands
1 parent 2e47f95 commit 2b6145b

File tree

11 files changed

+61
-79
lines changed

11 files changed

+61
-79
lines changed

rocketpool-cli/wallet/commands.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
2828
}
2929

3030
// Run
31-
return getStatus(c)
31+
return getStatus()
3232

3333
},
3434
},
@@ -67,7 +67,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
6767
}
6868

6969
// Run
70-
return initWallet(c)
70+
return initWallet(c.String("password"), c.Bool("confirm-mnemonic"), c.String("derivation-path"), c.GlobalBool("secure-session"))
7171

7272
},
7373
},
@@ -124,7 +124,14 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
124124
}
125125

126126
// Run
127-
return recoverWallet(c)
127+
return recoverWallet(
128+
c.String("password"),
129+
c.String("mnemonic"),
130+
c.String("address"),
131+
c.Bool("skip-validator-key-recovery"),
132+
c.String("derivation-path"),
133+
c.Uint("wallet-index"),
134+
)
128135

129136
},
130137
},
@@ -142,7 +149,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
142149
}
143150

144151
// Run
145-
return rebuildWallet(c)
152+
return rebuildWallet()
146153

147154
},
148155
},
@@ -190,7 +197,13 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
190197
}
191198

192199
// Run
193-
return testRecovery(c)
200+
return testRecovery(
201+
c.String("mnemonic"),
202+
c.String("address"),
203+
c.Bool("skip-validator-key-recovery"),
204+
c.String("derivation-path"),
205+
c.Uint("wallet-index"),
206+
)
194207

195208
},
196209
},
@@ -208,7 +221,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
208221
}
209222

210223
// Run
211-
return exportWallet(c)
224+
return exportWallet(c.GlobalBool("secure-session"))
212225

213226
},
214227
},
@@ -225,7 +238,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
225238
}
226239

227240
// Run
228-
return setEnsName(c, c.Args().Get(0))
241+
return setEnsName(c.Args().Get(0), c.Bool("yes"))
229242

230243
},
231244
},
@@ -242,7 +255,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
242255
}
243256

244257
// Run
245-
return purge(c)
258+
return purge(c.Parent().StringSlice("compose-file"))
246259

247260
},
248261
},
@@ -272,7 +285,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
272285
}
273286

274287
// Run
275-
return masquerade(c)
288+
return masquerade(c.String("address"), c.Bool("yes"))
276289

277290
},
278291
},
@@ -297,7 +310,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
297310
}
298311

299312
// Run
300-
return endMasquerade(c)
313+
return endMasquerade(c.Bool("yes"))
301314

302315
},
303316
},

rocketpool-cli/wallet/end-masquerade.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
88
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
99
"github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
10-
"github.com/urfave/cli"
1110
)
1211

13-
func endMasquerade(c *cli.Context) error {
12+
func endMasquerade(yes bool) error {
1413
// Get RP client
1514
rp := rocketpool.NewClient()
1615
defer rp.Close()
@@ -38,7 +37,7 @@ func endMasquerade(c *cli.Context) error {
3837
}
3938

4039
// Prompt for confirmation
41-
if !(c.Bool("yes") || prompt.Confirm("Are you sure you want to end masquerade mode?")) {
40+
if !(yes || prompt.Confirm("Are you sure you want to end masquerade mode?")) {
4241
fmt.Println("Cancelled.")
4342
return nil
4443
}

rocketpool-cli/wallet/ens-name.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
99
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
1010
promptcli "github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
11-
"github.com/urfave/cli"
1211
)
1312

14-
func setEnsName(c *cli.Context, name string) error {
13+
func setEnsName(name string, yes bool) error {
1514

1615
// Get RP client
1716
rp, err := rocketpool.NewClient().WithReady()
@@ -33,7 +32,7 @@ func setEnsName(c *cli.Context, name string) error {
3332
}
3433

3534
// Assign max fees
36-
err = gas.AssignMaxFeeAndLimit(estimateGasSetName.GasInfo, rp, c.Bool("yes"))
35+
err = gas.AssignMaxFeeAndLimit(estimateGasSetName.GasInfo, rp, yes)
3736
if err != nil {
3837
return err
3938
}

rocketpool-cli/wallet/export.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/urfave/cli"
8-
97
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
108
promptcli "github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
119
)
1210

13-
func exportWallet(c *cli.Context) error {
11+
func exportWallet(secureSession bool) error {
1412

1513
// Get RP client
1614
rp := rocketpool.NewClient()
@@ -26,7 +24,7 @@ func exportWallet(c *cli.Context) error {
2624
return nil
2725
}
2826

29-
if !c.GlobalBool("secure-session") {
27+
if !secureSession {
3028
// Check if stdout is interactive
3129
stat, err := os.Stdout.Stat()
3230
if err != nil {

rocketpool-cli/wallet/init.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package wallet
33
import (
44
"fmt"
55

6-
"github.com/urfave/cli"
7-
86
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
97
promptcli "github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
108
"github.com/rocket-pool/smartnode/shared/utils/term"
119
)
1210

13-
func initWallet(c *cli.Context) error {
11+
func initWallet(password string, confirmMnemonicFlag bool, derivationPath string, secureSession bool) error {
1412

1513
// Get RP client
1614
rp := rocketpool.NewClient()
@@ -27,17 +25,14 @@ func initWallet(c *cli.Context) error {
2725
}
2826

2927
// Prompt for user confirmation before printing sensitive information
30-
if !(c.GlobalBool("secure-session") ||
28+
if !(secureSession ||
3129
promptcli.ConfirmSecureSession("Creating a wallet will print sensitive information to your screen.")) {
3230
return nil
3331
}
3432

3533
// Set password if not set
3634
if !status.PasswordSet {
37-
var password string
38-
if c.String("password") != "" {
39-
password = c.String("password")
40-
} else {
35+
if password == "" {
4136
password = promptPassword()
4237
}
4338
if _, err := rp.SetPassword(password); err != nil {
@@ -46,7 +41,6 @@ func initWallet(c *cli.Context) error {
4641
}
4742

4843
// Get the derivation path
49-
derivationPath := c.String("derivation-path")
5044
if derivationPath != "" {
5145
fmt.Printf("Using a custom derivation path (%s).\n\n", derivationPath)
5246
}
@@ -68,7 +62,7 @@ func initWallet(c *cli.Context) error {
6862
fmt.Println("")
6963

7064
// Confirm mnemonic
71-
if !c.Bool("confirm-mnemonic") {
65+
if !confirmMnemonicFlag {
7266
confirmMnemonic(response.Mnemonic)
7367
}
7468

rocketpool-cli/wallet/masquerade.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
88
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
99
"github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
10-
"github.com/urfave/cli"
1110
)
1211

13-
func masquerade(c *cli.Context) error {
12+
func masquerade(addressFlag string, yes bool) error {
1413
// Get RP client
1514
rp := rocketpool.NewClient()
1615
defer rp.Close()
@@ -19,18 +18,17 @@ func masquerade(c *cli.Context) error {
1918
fmt.Println()
2019

2120
// Get address
22-
addressString := c.String("address")
23-
if addressString == "" {
24-
addressString = prompt.Prompt("Please enter an address to masquerade as:", "^0x[0-9a-fA-F]{40}$", "Invalid address")
21+
if addressFlag == "" {
22+
addressFlag = prompt.Prompt("Please enter an address to masquerade as:", "^0x[0-9a-fA-F]{40}$", "Invalid address")
2523
}
2624

27-
address, err := cliutils.ValidateAddress("address", addressString)
25+
address, err := cliutils.ValidateAddress("address", addressFlag)
2826
if err != nil {
2927
return err
3028
}
3129

3230
// Prompt for confirmation
33-
if !(c.Bool("yes") || prompt.Confirm("Are you sure you want to masquerade as %s?", color.LightBlue(addressString))) {
31+
if !(yes || prompt.Confirm("Are you sure you want to masquerade as %s?", color.LightBlue(address.Hex()))) {
3432
fmt.Println("Cancelled.")
3533
return nil
3634
}
@@ -41,7 +39,7 @@ func masquerade(c *cli.Context) error {
4139
return fmt.Errorf("error running masquerade: %w", err)
4240
}
4341

44-
fmt.Printf("Your node is now masquerading as address %s.\n", color.LightBlue(addressString))
42+
fmt.Printf("Your node is now masquerading as address %s.\n", color.LightBlue(address.Hex()))
4543

4644
return nil
4745
}

rocketpool-cli/wallet/purge.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package wallet
33
import (
44
"fmt"
55

6-
"github.com/urfave/cli"
7-
86
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
97
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
108
promptcli "github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
119
)
1210

13-
func purge(c *cli.Context) error {
11+
func purge(composeFiles []string) error {
1412

1513
// Get RP client
1614
rp := rocketpool.NewClient()
@@ -27,7 +25,6 @@ func purge(c *cli.Context) error {
2725
}
2826

2927
// Purge
30-
composeFiles := c.Parent().StringSlice("compose-file")
3128
err := rp.PurgeAllKeys(composeFiles)
3229
if err != nil {
3330
return fmt.Errorf("%w\n"+color.Red("THERE WAS AN ERROR DELETING YOUR KEYS. They most likely have not been deleted. Proceed with caution."), err)

rocketpool-cli/wallet/rebuild.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/urfave/cli"
8-
97
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
108
)
119

12-
func rebuildWallet(c *cli.Context) error {
10+
func rebuildWallet() error {
1311

1412
// Get RP client
1513
rp, err := rocketpool.NewClient().WithReady()

rocketpool-cli/wallet/recover.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
"strings"
77

88
"github.com/ethereum/go-ethereum/common"
9-
"github.com/urfave/cli"
109

1110
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
1211
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
1312
promptcli "github.com/rocket-pool/smartnode/shared/utils/cli/prompt"
1413
)
1514

16-
func recoverWallet(c *cli.Context) error {
15+
func recoverWallet(password, mnemonic, addressFlag string, skipValidatorKeyRecovery bool, derivationPath string, walletIndex uint) error {
1716

1817
// Get RP client
1918
rp, ready, err := rocketpool.NewClient().WithStatus()
@@ -46,10 +45,7 @@ func recoverWallet(c *cli.Context) error {
4645

4746
// Set password if not set
4847
if !status.PasswordSet {
49-
var password string
50-
if c.String("password") != "" {
51-
password = c.String("password")
52-
} else {
48+
if password == "" {
5349
password = promptPassword()
5450
}
5551
if _, err := rp.SetPassword(password); err != nil {
@@ -58,7 +54,6 @@ func recoverWallet(c *cli.Context) error {
5854
}
5955

6056
// Handle validator key recovery skipping
61-
skipValidatorKeyRecovery := c.Bool("skip-validator-key-recovery")
6257
if !skipValidatorKeyRecovery && !ready {
6358
fmt.Println(color.Yellow("Eth Clients are not available.") + " Validator keys cannot be recovered until they are synced and ready.")
6459
fmt.Println("You can recover them later with 'rocketpool wallet rebuild'")
@@ -70,10 +65,7 @@ func recoverWallet(c *cli.Context) error {
7065
}
7166

7267
// Prompt for mnemonic
73-
var mnemonic string
74-
if c.String("mnemonic") != "" {
75-
mnemonic = c.String("mnemonic")
76-
} else {
68+
if mnemonic == "" {
7769
mnemonic = PromptMnemonic()
7870
}
7971
mnemonic = strings.TrimSpace(mnemonic)
@@ -101,11 +93,9 @@ func recoverWallet(c *cli.Context) error {
10193
}
10294

10395
// Check for a search-by-address operation
104-
addressString := c.String("address")
105-
if addressString != "" {
106-
96+
if addressFlag != "" {
10797
// Get the address to search for
108-
address := common.HexToAddress(addressString)
98+
address := common.HexToAddress(addressFlag)
10999
fmt.Printf("Searching for the derivation path and index for wallet %s...\nNOTE: this may take several minutes depending on how large your wallet's index is.\n", address.Hex())
110100

111101
if !skipValidatorKeyRecovery {
@@ -139,13 +129,11 @@ func recoverWallet(c *cli.Context) error {
139129
} else {
140130

141131
// Get the derivation path
142-
derivationPath := c.String("derivation-path")
143132
if derivationPath != "" {
144133
fmt.Printf("Using a custom derivation path (%s).\n", derivationPath)
145134
}
146135

147136
// Get the wallet index
148-
walletIndex := c.Uint("wallet-index")
149137
if walletIndex != 0 {
150138
fmt.Printf("Using a custom wallet index (%d).\n", walletIndex)
151139
}

rocketpool-cli/wallet/status.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import (
44
"fmt"
55

66
"github.com/ethereum/go-ethereum/common"
7-
"github.com/urfave/cli"
87

98
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
109
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
1110
"github.com/rocket-pool/smartnode/shared/utils/cli/color"
1211
)
1312

14-
func getStatus(c *cli.Context) error {
13+
func getStatus() error {
1514

1615
// Get RP client
1716
rp := rocketpool.NewClient()

0 commit comments

Comments
 (0)