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
This commit is contained in:
Ivan Martinez 2020-07-28 18:58:11 -04:00 committed by GitHub
parent c0d6a231bf
commit 3a609f44b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 9 deletions

View File

@ -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))

View File

@ -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

View File

@ -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")
}