mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Improve Speed of Accounts Import (#6785)
* improve speed of import * better format * imports * Merge branch 'master' into fast-import * Merge refs/heads/master into fast-import * Merge refs/heads/master into fast-import * Merge refs/heads/master into fast-import * Merge refs/heads/master into fast-import
This commit is contained in:
parent
ec4de10001
commit
bd7046c790
@ -6,8 +6,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
@ -53,41 +53,25 @@ func ImportAccount(cliCtx *cli.Context) error {
|
||||
if err := wallet.SaveWallet(); err != nil {
|
||||
return errors.Wrap(err, "could not save wallet")
|
||||
}
|
||||
var accountsImported []string
|
||||
var pubKeysImported [][]byte
|
||||
if err := filepath.Walk(keysDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
accountsImported := make([]string, 0)
|
||||
pubKeysImported := make([][]byte, 0)
|
||||
files, err := ioutil.ReadDir(keysDir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read dir")
|
||||
}
|
||||
for i := 0; i < len(files); i++ {
|
||||
if files[i].IsDir() {
|
||||
continue
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
if !strings.HasPrefix(files[i].Name(), "keystore") {
|
||||
continue
|
||||
}
|
||||
|
||||
parentDir := filepath.Dir(path)
|
||||
matches, err := filepath.Glob(filepath.Join(parentDir, direct.KeystoreFileName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var keystoreFileFound bool
|
||||
for _, match := range matches {
|
||||
if match == path {
|
||||
keystoreFileFound = true
|
||||
}
|
||||
}
|
||||
if !keystoreFileFound {
|
||||
return nil
|
||||
}
|
||||
|
||||
accountName, pubKey, err := wallet.importKeystore(ctx, path)
|
||||
accountName, pubKey, err := wallet.importKeystore(ctx, filepath.Join(keysDir, files[i].Name()))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not import keystore")
|
||||
}
|
||||
accountsImported = append(accountsImported, accountName)
|
||||
pubKeysImported = append(pubKeysImported, pubKey)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "could not walk files")
|
||||
}
|
||||
|
||||
au := aurora.NewAurora(true)
|
||||
@ -99,19 +83,10 @@ func ImportAccount(cliCtx *cli.Context) error {
|
||||
if err := wallet.enterPasswordForAllAccounts(cliCtx, accountsImported, pubKeysImported); 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")
|
||||
}
|
||||
km, ok := keymanager.(*direct.Keymanager)
|
||||
if !ok {
|
||||
return errors.New("can only export accounts for a non-HD wallet")
|
||||
}
|
||||
if err := logAccountsImported(ctx, wallet, km, accountsImported); err != nil {
|
||||
return errors.Wrap(err, "could not log accounts imported")
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
"Successfully imported %s accounts, view all of them by running accounts-v2 list\n",
|
||||
au.BrightMagenta(strconv.Itoa(len(pubKeysImported))),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user