mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/geth: check before printing warning log
This commit is contained in:
parent
848ab4682b
commit
a3f494d977
2 changed files with 14 additions and 6 deletions
|
|
@ -205,7 +205,7 @@ func accountList(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tries unlocking the specified account a few times.
|
// tries unlocking the specified account a few times.
|
||||||
func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i int, passwords []string) (accounts.Account, string) {
|
func unlockAccount(ks *keystore.KeyStore, address string, i int, passwords []string) (accounts.Account, string) {
|
||||||
account, err := utils.MakeAddress(ks, address)
|
account, err := utils.MakeAddress(ks, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Could not list accounts: %v", err)
|
utils.Fatalf("Could not list accounts: %v", err)
|
||||||
|
|
@ -326,7 +326,7 @@ func accountUpdate(ctx *cli.Context) error {
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
|
|
||||||
for _, addr := range ctx.Args() {
|
for _, addr := range ctx.Args() {
|
||||||
account, oldPassword := unlockAccount(ctx, ks, addr, 0, nil)
|
account, oldPassword := unlockAccount(ks, addr, 0, nil)
|
||||||
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
|
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
|
||||||
if err := ks.Update(account, oldPassword, newPassword); err != nil {
|
if err := ks.Update(account, oldPassword, newPassword); err != nil {
|
||||||
utils.Fatalf("Could not update the account: %v", err)
|
utils.Fatalf("Could not update the account: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -397,6 +397,17 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
||||||
|
|
||||||
// unlockAccounts unlocks any account specifically requested.
|
// unlockAccounts unlocks any account specifically requested.
|
||||||
func unlockAccounts(ctx *cli.Context, stack *node.Node) {
|
func unlockAccounts(ctx *cli.Context, stack *node.Node) {
|
||||||
|
var unlocks []string
|
||||||
|
inputs := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
|
||||||
|
for _, input := range inputs {
|
||||||
|
if trimmed := strings.TrimSpace(input); trimmed != "" {
|
||||||
|
unlocks = append(unlocks, trimmed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Short circuit if there is no account to unlock.
|
||||||
|
if len(unlocks) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
// If insecure account unlocking is not allowed if node's APIs are exposed to external.
|
// If insecure account unlocking is not allowed if node's APIs are exposed to external.
|
||||||
// Print warning log to user and skip unlocking.
|
// Print warning log to user and skip unlocking.
|
||||||
if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
|
if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
|
||||||
|
|
@ -405,10 +416,7 @@ func unlockAccounts(ctx *cli.Context, stack *node.Node) {
|
||||||
}
|
}
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
passwords := utils.MakePasswordList(ctx)
|
passwords := utils.MakePasswordList(ctx)
|
||||||
unlocks := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
|
|
||||||
for i, account := range unlocks {
|
for i, account := range unlocks {
|
||||||
if trimmed := strings.TrimSpace(account); trimmed != "" {
|
unlockAccount(ks, account, i, passwords)
|
||||||
unlockAccount(ctx, ks, trimmed, i, passwords)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue