aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-06-18 23:20:00 +0800
committerzelig <viktor.tron@gmail.com>2015-07-03 06:28:11 +0800
commitfc2e33c594449e38b90bad2bd7b5c50f03b7f69d (patch)
tree8cd8fbf8f0ecb93234b2fb47df30e5e1b78d5173
parent1d72aaa0cd3a94e95c892a8b8b88a8a1ef59847e (diff)
downloadgo-tangerine-fc2e33c594449e38b90bad2bd7b5c50f03b7f69d.tar.gz
go-tangerine-fc2e33c594449e38b90bad2bd7b5c50f03b7f69d.tar.zst
go-tangerine-fc2e33c594449e38b90bad2bd7b5c50f03b7f69d.zip
unlock multiple passes and obsolete primary
* multiple passwords allowed in password file * split on "\n", sideeffect: chop trailing slashes. fixes common mistake <(echo 'pass') * remove accounts.Primary method * do not fall back to primary account for mining
-rw-r--r--accounts/account_manager.go13
-rw-r--r--accounts/accounts_test.go2
-rw-r--r--cmd/geth/js_test.go2
-rw-r--r--cmd/geth/main.go38
-rw-r--r--cmd/utils/flags.go2
-rw-r--r--eth/backend.go11
6 files changed, 27 insertions, 41 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index e79ec51a2..4519c8420 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -81,19 +81,6 @@ func (am *Manager) HasAccount(addr common.Address) bool {
return false
}
-func (am *Manager) Primary() (addr common.Address, err error) {
- addrs, err := am.keyStore.GetKeyAddresses()
- if os.IsNotExist(err) {
- return common.Address{}, ErrNoKeys
- } else if err != nil {
- return common.Address{}, err
- }
- if len(addrs) == 0 {
- return common.Address{}, ErrNoKeys
- }
- return addrs[0], nil
-}
-
func (am *Manager) DeleteAccount(address common.Address, auth string) error {
return am.keyStore.DeleteKey(address, auth)
}
diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go
index 6065fa8e4..8bd70880c 100644
--- a/accounts/accounts_test.go
+++ b/accounts/accounts_test.go
@@ -18,7 +18,7 @@ func TestSign(t *testing.T) {
pass := "" // not used but required by API
a1, err := am.NewAccount(pass)
toSign := randentropy.GetEntropyCSPRNG(32)
- am.Unlock(a1.Address, "", 0)
+ am.Unlock(a1.Address, "")
_, err = am.Sign(a1, toSign)
if err != nil {
diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go
index cfbe26bee..fc2444a7b 100644
--- a/cmd/geth/js_test.go
+++ b/cmd/geth/js_test.go
@@ -140,7 +140,7 @@ func TestAccounts(t *testing.T) {
defer os.RemoveAll(tmp)
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
- checkEvalJSON(t, repl, `eth.coinbase`, `"`+testAddress+`"`)
+ checkEvalJSON(t, repl, `eth.coinbase`, `"`+common.Address{}.Hex()+`"`)
val, err := repl.re.Run(`personal.newAccount("password")`)
if err != nil {
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index be40d5137..b20c6d85d 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -153,9 +153,12 @@ Note that exporting your key in unencrypted format is NOT supported.
Keys are stored under <DATADIR>/keys.
It is safe to transfer the entire directory or the individual keys therein
-between ethereum nodes.
+between ethereum nodes by simply copying.
Make sure you backup your keys regularly.
+In order to use your account to send transactions, you need to unlock them using the
+'--unlock' option. The argument is a comma
+
And finally. DO NOT FORGET YOUR PASSWORD.
`,
Subcommands: []cli.Command{
@@ -430,7 +433,7 @@ func execJSFiles(ctx *cli.Context) {
ethereum.WaitForShutdown()
}
-func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (passphrase string) {
+func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string, i int) {
var err error
// Load startup keys. XXX we are going to need a different format
@@ -441,7 +444,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
attempts := 3
for tries := 0; tries < attempts; tries++ {
msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", account, tries+1, attempts)
- passphrase = getPassPhrase(ctx, msg, false)
+ passphrase := getPassPhrase(ctx, msg, false, i)
err = am.Unlock(common.HexToAddress(account), passphrase)
if err == nil {
break
@@ -451,7 +454,6 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
utils.Fatalf("Unlock account failed '%v'", err)
}
fmt.Printf("Account '%s' unlocked.\n", account)
- return
}
func blockRecovery(ctx *cli.Context) {
@@ -492,16 +494,12 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
accounts := strings.Split(account, " ")
- for _, account := range accounts {
+ for i, account := range accounts {
if len(account) > 0 {
if account == "primary" {
- primaryAcc, err := am.Primary()
- if err != nil {
- utils.Fatalf("no primary account: %v", err)
- }
- account = primaryAcc.Hex()
+ utils.Fatalf("the 'primary' keyword is deprecated. You can use indexes, but the indexes are not permanent, they can change if you add external keys, export your keys or copy your keystore to another node.")
}
- unlockAccount(ctx, am, account)
+ unlockAccount(ctx, am, account, i)
}
}
// Start auxiliary services if enabled.
@@ -535,7 +533,7 @@ func accountList(ctx *cli.Context) {
}
}
-func getPassPhrase(ctx *cli.Context, desc string, confirmation bool) (passphrase string) {
+func getPassPhrase(ctx *cli.Context, desc string, confirmation bool, i int) (passphrase string) {
passfile := ctx.GlobalString(utils.PasswordFileFlag.Name)
if len(passfile) == 0 {
fmt.Println(desc)
@@ -559,14 +557,22 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool) (passphrase
if err != nil {
utils.Fatalf("Unable to read password file '%s': %v", passfile, err)
}
- passphrase = string(passbytes)
+ // this is backwards compatible if the same password unlocks several accounts
+ // it also has the consequence that trailing newlines will not count as part
+ // of the password, so --password <(echo -n 'pass') will now work without -n
+ passphrases := strings.Split(string(passbytes), "\n")
+ if i >= len(passphrases) {
+ passphrase = passphrases[len(passphrases)-1]
+ } else {
+ passphrase = passphrases[i]
+ }
}
return
}
func accountCreate(ctx *cli.Context) {
am := utils.MakeAccountManager(ctx)
- passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true)
+ passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
acct, err := am.NewAccount(passphrase)
if err != nil {
utils.Fatalf("Could not create the account: %v", err)
@@ -585,7 +591,7 @@ func importWallet(ctx *cli.Context) {
}
am := utils.MakeAccountManager(ctx)
- passphrase := getPassPhrase(ctx, "", false)
+ passphrase := getPassPhrase(ctx, "", false, 0)
acct, err := am.ImportPreSaleKey(keyJson, passphrase)
if err != nil {
@@ -600,7 +606,7 @@ func accountImport(ctx *cli.Context) {
utils.Fatalf("keyfile must be given as argument")
}
am := utils.MakeAccountManager(ctx)
- passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true)
+ passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
acct, err := am.Import(keyfile, passphrase)
if err != nil {
utils.Fatalf("Could not create the account: %v", err)
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 6f319eb40..7460f51e1 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -133,7 +133,7 @@ var (
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
- Usage: "Unlock the account given until this program exits (prompts for password). '--unlock primary' unlocks the primary account",
+ Usage: "Unlock the account given until this program exits (prompts for password). '--unlock n' unlocks the n-th account in order or creation.",
Value: "",
}
PasswordFileFlag = cli.StringFlag{
diff --git a/eth/backend.go b/eth/backend.go
index d6ad3381d..ce774ba1b 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -464,15 +464,8 @@ func (s *Ethereum) StartMining(threads int) error {
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
eb = s.etherbase
if (eb == common.Address{}) {
- primary, err := s.accountManager.Primary()
- if err != nil {
- return eb, err
- }
- if (primary == common.Address{}) {
- err = fmt.Errorf("no accounts found")
- return eb, err
- }
- eb = primary
+ err = fmt.Errorf("no accounts found")
+ return eb, err
}
return eb, nil
}