aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-07-03 11:56:20 +0800
committerzelig <viktor.tron@gmail.com>2015-07-03 14:52:37 +0800
commit1959346793bdee469f68841843dd383cf801aba1 (patch)
tree12d53e0974ae96fdc27f8ed0e217565c5530b143 /cmd/geth
parentfc17a527bc2bd07fc30e16d161059a441042d5f1 (diff)
downloaddexon-1959346793bdee469f68841843dd383cf801aba1.tar
dexon-1959346793bdee469f68841843dd383cf801aba1.tar.gz
dexon-1959346793bdee469f68841843dd383cf801aba1.tar.bz2
dexon-1959346793bdee469f68841843dd383cf801aba1.tar.lz
dexon-1959346793bdee469f68841843dd383cf801aba1.tar.xz
dexon-1959346793bdee469f68841843dd383cf801aba1.tar.zst
dexon-1959346793bdee469f68841843dd383cf801aba1.zip
account update: migrate or change password
* account.Update * KeyStore.Cleanup * fix dir rm for old format deleteKey
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/main.go68
1 files changed, 61 insertions, 7 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 673a08d45..ffd26a7c2 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -190,6 +190,33 @@ password to file or expose in any other way.
`,
},
{
+ Action: accountUpdate,
+ Name: "update",
+ Usage: "update an existing account",
+ Description: `
+
+ ethereum account update <address>
+
+Update an existing account.
+
+The account is saved in the newest version in encrypted format, you are prompted
+for a passphrase to unlock the account and another to save the updated file.
+
+This same command can therefore be used to migrate an account of a deprecated
+format to the newest format or change the password for an account.
+
+For non-interactive use the passphrase can be specified with the --password flag:
+
+ ethereum --password <passwordfile> account new
+
+Since only one password can be given, only format update can be performed,
+changing your password is only possible interactively.
+
+Note that account update has the a side effect that the order of your accounts
+changes.
+ `,
+ },
+ {
Action: accountImport,
Name: "import",
Usage: "import a private key into a new account",
@@ -433,19 +460,30 @@ func execJSFiles(ctx *cli.Context) {
ethereum.WaitForShutdown()
}
-func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string, i int) {
+func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
var err error
// Load startup keys. XXX we are going to need a different format
- if !((len(account) == 40) || (len(account) == 42)) { // with or without 0x
- utils.Fatalf("Invalid account address '%s'", account)
+ if !((len(addr) == 40) || (len(addr) == 42)) { // with or without 0x
+ var index int
+ index, err = strconv.Atoi(addr)
+ if err != nil {
+ utils.Fatalf("Invalid account address '%s'", addr)
+ }
+
+ addrHex, err = am.AddressByIndex(index)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ } else {
+ addrHex = addr
}
// Attempt to unlock the account 3 times
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, i)
- err = am.Unlock(common.HexToAddress(account), passphrase)
+ msg := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", addr, tries+1, attempts)
+ auth = getPassPhrase(ctx, msg, false, i)
+ err = am.Unlock(common.HexToAddress(addrHex), auth)
if err == nil {
break
}
@@ -453,7 +491,8 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string, i int
if err != nil {
utils.Fatalf("Unlock account failed '%v'", err)
}
- fmt.Printf("Account '%s' unlocked.\n", account)
+ fmt.Printf("Account '%s' unlocked.\n", addr)
+ return
}
func blockRecovery(ctx *cli.Context) {
@@ -578,6 +617,21 @@ func accountCreate(ctx *cli.Context) {
fmt.Printf("Address: %x\n", acct)
}
+func accountUpdate(ctx *cli.Context) {
+ am := utils.MakeAccountManager(ctx)
+ arg := ctx.Args().First()
+ if len(arg) == 0 {
+ utils.Fatalf("account address or index must be given as argument")
+ }
+
+ addr, authFrom := unlockAccount(ctx, am, arg, 0)
+ authTo := getPassPhrase(ctx, "Please give a new password. Do not forget this password.", true, 0)
+ err := am.Update(common.HexToAddress(addr), authFrom, authTo)
+ if err != nil {
+ utils.Fatalf("Could not update the account: %v", err)
+ }
+}
+
func importWallet(ctx *cli.Context) {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {