Skip to content

Commit cefa2ab

Browse files
authored
Merge pull request #21173 from karalabe/faucet-delete-oldaccs
cmd/faucet: delete old keystore when importing new faucet key
2 parents 201e345 + b1b75f0 commit cefa2ab

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

accounts/keystore/keystore.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,19 +449,25 @@ func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (ac
449449
}
450450
ks.importMu.Lock()
451451
defer ks.importMu.Unlock()
452+
452453
if ks.cache.hasAddress(key.Address) {
453-
return accounts.Account{}, ErrAccountAlreadyExists
454+
return accounts.Account{
455+
Address: key.Address,
456+
}, ErrAccountAlreadyExists
454457
}
455458
return ks.importKey(key, newPassphrase)
456459
}
457460

458461
// ImportECDSA stores the given key into the key directory, encrypting it with the passphrase.
459462
func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (accounts.Account, error) {
460-
key := newKeyFromECDSA(priv)
461463
ks.importMu.Lock()
462464
defer ks.importMu.Unlock()
465+
466+
key := newKeyFromECDSA(priv)
463467
if ks.cache.hasAddress(key.Address) {
464-
return accounts.Account{}, ErrAccountAlreadyExists
468+
return accounts.Account{
469+
Address: key.Address,
470+
}, ErrAccountAlreadyExists
465471
}
466472
return ks.importKey(key, passphrase)
467473
}

cmd/faucet/faucet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func main() {
162162
if blob, err = ioutil.ReadFile(*accPassFlag); err != nil {
163163
log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err)
164164
}
165-
// Delete trailing newline in password
166165
pass := strings.TrimSuffix(string(blob), "\n")
167166

168167
ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP)
@@ -173,8 +172,9 @@ func main() {
173172
if err != nil && err != keystore.ErrAccountAlreadyExists {
174173
log.Crit("Failed to import faucet signer account", "err", err)
175174
}
176-
ks.Unlock(acc, pass)
177-
175+
if err := ks.Unlock(acc, pass); err != nil {
176+
log.Crit("Failed to unlock faucet signer account", "err", err)
177+
}
178178
// Assemble and start the faucet light service
179179
faucet, err := newFaucet(genesis, *ethPortFlag, enodes, *netFlag, *statsFlag, ks, website.Bytes())
180180
if err != nil {

0 commit comments

Comments
 (0)