mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
Implement and enable 'unlock' flag
This commit is contained in:
parent
30641c06b1
commit
8de6903eee
3 changed files with 41 additions and 0 deletions
|
|
@ -663,6 +663,25 @@ func (c *Config) buildEth(stack *node.Node) (*ethconfig.Config, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unlock accounts
|
||||||
|
if len(c.Accounts.Unlock) > 0 {
|
||||||
|
if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
|
||||||
|
return nil, fmt.Errorf("Account unlock with HTTP access is forbidden!")
|
||||||
|
}
|
||||||
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
|
passwords, err := MakePasswordListFromFile(c.Accounts.PasswordFile)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(passwords) < len(c.Accounts.Unlock) {
|
||||||
|
return nil, fmt.Errorf("Number of passwords provided (%v) is less than number of accounts (%v) to unlock",
|
||||||
|
len(passwords), len(c.Accounts.Unlock))
|
||||||
|
}
|
||||||
|
for i, account := range c.Accounts.Unlock {
|
||||||
|
ks.Unlock(accounts.Account{Address: common.HexToAddress(account)}, passwords[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update for developer mode
|
// update for developer mode
|
||||||
if c.Developer.Enabled {
|
if c.Developer.Enabled {
|
||||||
// Get a keystore
|
// Get a keystore
|
||||||
|
|
@ -990,3 +1009,16 @@ func Hostname() string {
|
||||||
}
|
}
|
||||||
return hostname
|
return hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakePasswordListFromFile(path string) ([]string, error) {
|
||||||
|
text, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to read password file: %v", err)
|
||||||
|
}
|
||||||
|
lines := strings.Split(string(text), "\n")
|
||||||
|
// Sanitise DOS line endings.
|
||||||
|
for i := range lines {
|
||||||
|
lines[i] = strings.TrimRight(lines[i], "\r")
|
||||||
|
}
|
||||||
|
return lines, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,3 +153,10 @@ func TestConfigBootnodesDefault(t *testing.T) {
|
||||||
assert.Len(t, cfg.P2P.BootstrapNodes, 1)
|
assert.Len(t, cfg.P2P.BootstrapNodes, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMakePasswordListFromFile(t *testing.T) {
|
||||||
|
t.Run("ReadPasswordFile", func(t *testing.T) {
|
||||||
|
result, _ := MakePasswordListFromFile("./testdata/password.txt")
|
||||||
|
assert.Equal(t, []string{"test1", "test2"}, result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
2
internal/cli/server/testdata/password.txt
vendored
Normal file
2
internal/cli/server/testdata/password.txt
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
test1
|
||||||
|
test2
|
||||||
Loading…
Reference in a new issue