Skip to content

Commit 46e5583

Browse files
karalabefjl
authored andcommitted
cmd/utils, eth: init etherbase from within eth (#15528)
1 parent bf62acf commit 46e5583

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎cmd/utils/flags.go‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,12 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
746746
if err != nil || index < 0 {
747747
return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account)
748748
}
749+
log.Warn("-------------------------------------------------------------------")
750+
log.Warn("Referring to accounts by order in the keystore folder is dangerous!")
751+
log.Warn("This functionality is deprecated and will be removed in the future!")
752+
log.Warn("Please use explicit addresses! (can search via `geth account list`)")
753+
log.Warn("-------------------------------------------------------------------")
754+
749755
accs := ks.Accounts()
750756
if len(accs) <= index {
751757
return accounts.Account{}, fmt.Errorf("index %d higher than number of accounts %d", index, len(accs))
@@ -762,15 +768,6 @@ func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
762768
Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
763769
}
764770
cfg.Etherbase = account.Address
765-
return
766-
}
767-
accounts := ks.Accounts()
768-
if (cfg.Etherbase == common.Address{}) {
769-
if len(accounts) > 0 {
770-
cfg.Etherbase = accounts[0].Address
771-
} else {
772-
log.Warn("No etherbase set and no accounts found as default")
773-
}
774771
}
775772
}
776773

‎eth/backend.go‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,17 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
310310
}
311311
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
312312
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
313-
return accounts[0].Address, nil
313+
etherbase := accounts[0].Address
314+
315+
s.lock.Lock()
316+
s.etherbase = etherbase
317+
s.lock.Unlock()
318+
319+
log.Info("Etherbase automatically configured", "address", etherbase)
320+
return etherbase, nil
314321
}
315322
}
316-
return common.Address{}, fmt.Errorf("etherbase address must be explicitly specified")
323+
return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
317324
}
318325

319326
// set in js console via admin interface or wrapper from cli flags

0 commit comments

Comments
 (0)