mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-30 00:23:46 +00:00
fix: write key error
This commit is contained in:
parent
d831ad6c25
commit
fb7860e43f
1 changed files with 9 additions and 1 deletions
|
|
@ -498,13 +498,21 @@ func setPrivateKey(ctx *cli.Context, config *Config) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := os.Stat(filepath.Join(config.DataDir, privateKeyFileName)); err == nil {
|
||||
fullPath := filepath.Join(config.DataDir, privateKeyFileName)
|
||||
if _, err := os.Stat(fullPath); err == nil {
|
||||
log.Info("Loading private key from file", "datadir", config.DataDir, "file", privateKeyFileName)
|
||||
privateKey, err = readPrivateKey(config, privateKeyFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if os.IsNotExist(err) {
|
||||
file, err := os.Create(fullPath)
|
||||
if err != nil {
|
||||
log.Error("Failed to create file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
}
|
||||
log.Info("Creating new private key")
|
||||
privateKey, err = crypto.GenerateKey()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue