Skip to content

Commit f1d7c0f

Browse files
rkapkarauljordanprylabs-bulldozer[bot]
authored
Create a new wallet on accounts import only when necessary (#8801)
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
1 parent 3d96e3c commit f1d7c0f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

validator/accounts/accounts_import.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ type ImportAccountsConfig struct {
8383
// values necessary to run the function.
8484
func ImportAccountsCli(cliCtx *cli.Context) error {
8585
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
86+
walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag)
87+
if err != nil {
88+
return nil, err
89+
}
90+
exists, err := wallet.Exists(walletDir)
91+
if err != nil {
92+
return nil, errors.Wrap(err, wallet.CheckExistsErrMsg)
93+
}
94+
if exists {
95+
isValid, err := wallet.IsValid(walletDir)
96+
if err != nil {
97+
return nil, errors.Wrap(err, wallet.CheckValidityErrMsg)
98+
}
99+
if !isValid {
100+
return nil, errors.New(wallet.InvalidWalletErrMsg)
101+
}
102+
walletPassword, err := wallet.InputPassword(
103+
cliCtx,
104+
flags.WalletPasswordFileFlag,
105+
wallet.PasswordPromptText,
106+
false, /* Do not confirm password */
107+
wallet.ValidateExistingPass,
108+
)
109+
if err != nil {
110+
return nil, err
111+
}
112+
return wallet.OpenWallet(cliCtx.Context, &wallet.Config{
113+
WalletDir: walletDir,
114+
WalletPassword: walletPassword,
115+
})
116+
}
117+
86118
cfg, err := extractWalletCreationConfigFromCli(cliCtx, keymanager.Imported)
87119
if err != nil {
88120
return nil, err

validator/accounts/wallet/wallet.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context
177177
if err != nil {
178178
return nil, err
179179
}
180-
walletPassword, err := inputPassword(
180+
walletPassword, err := InputPassword(
181181
cliCtx,
182182
flags.WalletPasswordFileFlag,
183183
PasswordPromptText,
@@ -414,7 +414,9 @@ func readKeymanagerKindFromWalletPath(walletPath string) (keymanager.Kind, error
414414
return 0, errors.New("no keymanager folder (imported, remote, derived) found in wallet path")
415415
}
416416

417-
func inputPassword(
417+
// InputPassword prompts for a password and optionally for password confirmation.
418+
// The password is validated according to custom rules.
419+
func InputPassword(
418420
cliCtx *cli.Context,
419421
passwordFileFlag *cli.StringFlag,
420422
promptText string,

0 commit comments

Comments
 (0)