mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
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>
This commit is contained in:
@@ -83,6 +83,38 @@ type ImportAccountsConfig struct {
|
||||
// values necessary to run the function.
|
||||
func ImportAccountsCli(cliCtx *cli.Context) error {
|
||||
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
|
||||
walletDir, err := prompt.InputDirectory(cliCtx, prompt.WalletDirPromptText, flags.WalletDirFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exists, err := wallet.Exists(walletDir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, wallet.CheckExistsErrMsg)
|
||||
}
|
||||
if exists {
|
||||
isValid, err := wallet.IsValid(walletDir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, wallet.CheckValidityErrMsg)
|
||||
}
|
||||
if !isValid {
|
||||
return nil, errors.New(wallet.InvalidWalletErrMsg)
|
||||
}
|
||||
walletPassword, err := wallet.InputPassword(
|
||||
cliCtx,
|
||||
flags.WalletPasswordFileFlag,
|
||||
wallet.PasswordPromptText,
|
||||
false, /* Do not confirm password */
|
||||
wallet.ValidateExistingPass,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wallet.OpenWallet(cliCtx.Context, &wallet.Config{
|
||||
WalletDir: walletDir,
|
||||
WalletPassword: walletPassword,
|
||||
})
|
||||
}
|
||||
|
||||
cfg, err := extractWalletCreationConfigFromCli(cliCtx, keymanager.Imported)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -177,7 +177,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
walletPassword, err := inputPassword(
|
||||
walletPassword, err := InputPassword(
|
||||
cliCtx,
|
||||
flags.WalletPasswordFileFlag,
|
||||
PasswordPromptText,
|
||||
@@ -414,7 +414,9 @@ func readKeymanagerKindFromWalletPath(walletPath string) (keymanager.Kind, error
|
||||
return 0, errors.New("no keymanager folder (imported, remote, derived) found in wallet path")
|
||||
}
|
||||
|
||||
func inputPassword(
|
||||
// InputPassword prompts for a password and optionally for password confirmation.
|
||||
// The password is validated according to custom rules.
|
||||
func InputPassword(
|
||||
cliCtx *cli.Context,
|
||||
passwordFileFlag *cli.StringFlag,
|
||||
promptText string,
|
||||
|
||||
Reference in New Issue
Block a user