From b1b75f00893ed9e290e8466c86e601ab1fe63bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 4 Jun 2020 10:22:11 +0300 Subject: [PATCH] accounts/keystore, cmd/faucet: return old account to allow unlock --- accounts/keystore/keystore.go | 12 +++++++++--- cmd/faucet/faucet.go | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 80458a12fe..eb91edb5a2 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -449,19 +449,25 @@ func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (ac } ks.importMu.Lock() defer ks.importMu.Unlock() + if ks.cache.hasAddress(key.Address) { - return accounts.Account{}, ErrAccountAlreadyExists + return accounts.Account{ + Address: key.Address, + }, ErrAccountAlreadyExists } return ks.importKey(key, newPassphrase) } // ImportECDSA stores the given key into the key directory, encrypting it with the passphrase. func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (accounts.Account, error) { - key := newKeyFromECDSA(priv) ks.importMu.Lock() defer ks.importMu.Unlock() + + key := newKeyFromECDSA(priv) if ks.cache.hasAddress(key.Address) { - return accounts.Account{}, ErrAccountAlreadyExists + return accounts.Account{ + Address: key.Address, + }, ErrAccountAlreadyExists } return ks.importKey(key, passphrase) } diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index c4cce57cef..5a905c4f12 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -162,7 +162,6 @@ func main() { if blob, err = ioutil.ReadFile(*accPassFlag); err != nil { log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err) } - // Delete trailing newline in password pass := strings.TrimSuffix(string(blob), "\n") ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP) @@ -173,8 +172,9 @@ func main() { if err != nil && err != keystore.ErrAccountAlreadyExists { log.Crit("Failed to import faucet signer account", "err", err) } - ks.Unlock(acc, pass) - + if err := ks.Unlock(acc, pass); err != nil { + log.Crit("Failed to unlock faucet signer account", "err", err) + } // Assemble and start the faucet light service faucet, err := newFaucet(genesis, *ethPortFlag, enodes, *netFlag, *statsFlag, ks, website.Bytes()) if err != nil {