mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
accounts/keystore: Fix to properly init key directory
This commit is contained in:
parent
5120a06d70
commit
bf7da812d1
3 changed files with 30 additions and 15 deletions
|
|
@ -412,13 +412,23 @@ func (ks *KeyStore) expire(addr common.Address, u *unlocked, timeout time.Durati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAccount generates a new key and stores it into the key directory,
|
// CreateNewAccount generates a new key and stores it into the key directory,
|
||||||
// encrypting it with the passphrase.
|
// encrypting it with the passphrase.
|
||||||
func (ks *KeyStore) NewAccount(passphrase string) (accounts.Account, error) {
|
func (ks *KeyStore) CreateNewAccount(passphrase string) (accounts.Account, error) {
|
||||||
_, account, err := storeNewKey(ks.storage, crand.Reader, passphrase)
|
_, account, err := storeNewKey(ks.storage, crand.Reader, passphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return accounts.Account{}, err
|
return accounts.Account{}, err
|
||||||
}
|
}
|
||||||
|
return account, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAccount generates a new key and stores it into the key directory,
|
||||||
|
// encrypting it with the passphrase, and adds it to the cache
|
||||||
|
func (ks *KeyStore) NewAccount(passphrase string) (accounts.Account, error) {
|
||||||
|
account, err := ks.CreateNewAccount(passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return account, err
|
||||||
|
}
|
||||||
// Add the account to the cache immediately rather
|
// Add the account to the cache immediately rather
|
||||||
// than waiting for file system notifications to pick it up.
|
// than waiting for file system notifications to pick it up.
|
||||||
ks.cache.add(account)
|
ks.cache.add(account)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/console"
|
"github.com/ethereum/go-ethereum/console"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -292,17 +293,10 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
|
||||||
// accountCreate creates a new account into the keystore defined by the CLI flags.
|
// accountCreate creates a new account into the keystore defined by the CLI flags.
|
||||||
func accountCreate(ctx *cli.Context) error {
|
func accountCreate(ctx *cli.Context) error {
|
||||||
cfg := createConfig(ctx)
|
cfg := createConfig(ctx)
|
||||||
scryptN := keystore.StandardScryptN
|
ks, _, err := node.MakeKeystoreBackend(&cfg.Node, false)
|
||||||
scryptP := keystore.StandardScryptP
|
|
||||||
|
|
||||||
if cfg.Node.UseLightweightKDF {
|
|
||||||
scryptN = keystore.LightScryptN
|
|
||||||
scryptP = keystore.LightScryptP
|
|
||||||
}
|
|
||||||
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
|
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
|
||||||
ks := keystore.NewUninitializedKeyStore(cfg.Node.KeyStoreDir, scryptN, scryptP)
|
account, err := ks.CreateNewAccount(password)
|
||||||
|
|
||||||
account, err := ks.NewAccount(password)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Failed to create account: %v", err)
|
utils.Fatalf("Failed to create account: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,7 @@ func (c *Config) parsePersistentNodes(path string) []*discover.Node {
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
|
func MakeKeystoreBackend(conf *Config, loadKeys bool) (*keystore.KeyStore, string, error) {
|
||||||
scryptN := keystore.StandardScryptN
|
scryptN := keystore.StandardScryptN
|
||||||
scryptP := keystore.StandardScryptP
|
scryptP := keystore.StandardScryptP
|
||||||
if conf.UseLightweightKDF {
|
if conf.UseLightweightKDF {
|
||||||
|
|
@ -395,10 +395,21 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
|
||||||
if err := os.MkdirAll(keydir, 0700); err != nil {
|
if err := os.MkdirAll(keydir, 0700); err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
// Assemble the account manager and supported backends
|
if !loadKeys {
|
||||||
backends := []accounts.Backend{
|
return keystore.NewUninitializedKeyStore(keydir, scryptN, scryptP), ephemeral, nil
|
||||||
keystore.NewKeyStore(keydir, scryptN, scryptP),
|
|
||||||
}
|
}
|
||||||
|
return keystore.NewKeyStore(keydir, scryptN, scryptP), ephemeral, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
|
||||||
|
|
||||||
|
ks, ephemeral, err := MakeKeystoreBackend(conf, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
// Assemble the account manager and supported backends
|
||||||
|
|
||||||
|
backends := []accounts.Backend{ks}
|
||||||
if !conf.NoUSB {
|
if !conf.NoUSB {
|
||||||
// Start a USB hub for Ledger hardware wallets
|
// Start a USB hub for Ledger hardware wallets
|
||||||
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
|
if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue