From 3a609f44b97a2d1cc17c5abdee3ffa0b87282ee2 Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Tue, 28 Jul 2020 18:58:11 -0400 Subject: [PATCH] Accounts-V2: Minor fixes for logging (#6751) * Fixes for accounts-v2 * Merge branch 'master' into fixes * Undo wallet changes * Merge branch 'fixes' of github.com:prysmaticlabs/prysm into fixes * Merge refs/heads/master into fixes --- validator/accounts/v2/accounts_import.go | 30 ++++++++++++++++++------ validator/accounts/v2/accounts_list.go | 2 +- validator/accounts/v2/wallet.go | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/validator/accounts/v2/accounts_import.go b/validator/accounts/v2/accounts_import.go index 571d21f45..0ce9afdfb 100644 --- a/validator/accounts/v2/accounts_import.go +++ b/validator/accounts/v2/accounts_import.go @@ -8,7 +8,9 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" + "github.com/dustin/go-humanize" "github.com/logrusorgru/aurora" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/shared/petnames" @@ -92,15 +94,20 @@ func ImportAccount(cliCtx *cli.Context) error { if err != nil { return errors.Wrap(err, "could not import keystore") } - if err := wallet.enterPasswordForAccount(cliCtx, accountName); err != nil { - return errors.Wrap(err, "could not verify password for keystore") - } accountsImported = append(accountsImported, accountName) return nil }); err != nil { return errors.Wrap(err, "could not walk files") } + au := aurora.NewAurora(true) + fmt.Printf("Importing accounts: %s\n", au.BrightGreen(strings.Join(accountsImported, ", ")).Bold()) + for _, accountName := range accountsImported { + if err := wallet.enterPasswordForAccount(cliCtx, accountName); err != nil { + return errors.Wrap(err, "could not verify password for keystore") + } + } + keymanager, err := wallet.InitializeKeymanager(context.Background(), true /* skip mnemonic confirm */) if err != nil { return errors.Wrap(err, "could not initialize keymanager") @@ -109,7 +116,7 @@ func ImportAccount(cliCtx *cli.Context) error { if !ok { return errors.New("can only export accounts for a non-HD wallet") } - if err := logAccountsImported(wallet, km, accountsImported); err != nil { + if err := logAccountsImported(ctx, wallet, km, accountsImported); err != nil { return errors.Wrap(err, "could not log accounts imported") } @@ -137,7 +144,7 @@ func (w *Wallet) importKeystore(ctx context.Context, keystoreFilePath string) (s return accountName, nil } -func logAccountsImported(wallet *Wallet, keymanager *direct.Keymanager, accountNames []string) error { +func logAccountsImported(ctx context.Context, wallet *Wallet, keymanager *direct.Keymanager, accountNames []string) error { au := aurora.NewAurora(true) numAccounts := au.BrightYellow(len(accountNames)) @@ -149,13 +156,22 @@ func logAccountsImported(wallet *Wallet, keymanager *direct.Keymanager, accountN } for _, accountName := range accountNames { fmt.Println("") - fmt.Printf("%s\n", au.BrightGreen(accountName).Bold()) + // Retrieve the account creation timestamp. + keystoreFileName, err := wallet.FileNameAtPath(ctx, accountName, direct.KeystoreFileName) + if err != nil { + return errors.Wrapf(err, "could not get keystore file name for account: %s", accountName) + } + unixTimestamp, err := AccountTimestamp(keystoreFileName) + if err != nil { + return errors.Wrap(err, "could not get timestamp from keystore file name") + } + fmt.Printf("%s | Created %s\n", au.BrightGreen(accountName).Bold(), humanize.Time(unixTimestamp)) publicKey, err := keymanager.PublicKeyForAccount(accountName) if err != nil { return errors.Wrap(err, "could not get public key") } - fmt.Printf("%s %#x\n", au.BrightMagenta("[public key]").Bold(), publicKey) + fmt.Printf("%s %#x\n", au.BrightMagenta("[validating public key]").Bold(), publicKey) dirPath := au.BrightCyan("(wallet dir)") fmt.Printf("%s %s\n", dirPath, filepath.Join(wallet.AccountsDir(), accountName)) diff --git a/validator/accounts/v2/accounts_list.go b/validator/accounts/v2/accounts_list.go index fa4e8d8a1..1e862e6a2 100644 --- a/validator/accounts/v2/accounts_list.go +++ b/validator/accounts/v2/accounts_list.go @@ -103,7 +103,7 @@ func listDirectKeymanagerAccounts( if err != nil { return errors.Wrap(err, "could not get timestamp from keystore file name") } - fmt.Printf("%s | %s\n", au.BrightGreen(accountNames[i]).Bold(), humanize.Time(unixTimestamp)) + fmt.Printf("%s | Created %s\n", au.BrightGreen(accountNames[i]).Bold(), humanize.Time(unixTimestamp)) fmt.Printf("%s %#x\n", au.BrightMagenta("[validating public key]").Bold(), pubKeys[i]) if !showDepositData { continue diff --git a/validator/accounts/v2/wallet.go b/validator/accounts/v2/wallet.go index 291f2c11b..1dd65b848 100644 --- a/validator/accounts/v2/wallet.go +++ b/validator/accounts/v2/wallet.go @@ -403,7 +403,7 @@ func (w *Wallet) enterPasswordForAccount(cliCtx *cli.Context, accountName string // Loop asking for the password until the user enters it correctly. for attemptingPassword { // Ask the user for the password to their account. - password, err = inputWeakPassword(cliCtx, fmt.Sprintf(passwordForAccountPromptText, accountName)) + password, err = inputWeakPassword(cliCtx, fmt.Sprintf(passwordForAccountPromptText, au.BrightGreen(accountName))) if err != nil { return errors.Wrap(err, "could not input password") }