@@ -189,6 +189,33 @@ Note, this is meant to be used for testing only, it is a bad idea to save your
189189password to file or expose in any other way.
190190 ` ,
191191 },
192+ {
193+ Action : accountUpdate ,
194+ Name : "update" ,
195+ Usage : "update an existing account" ,
196+ Description : `
197+
198+ ethereum account update <address>
199+
200+ Update an existing account.
201+
202+ The account is saved in the newest version in encrypted format, you are prompted
203+ for a passphrase to unlock the account and another to save the updated file.
204+
205+ This same command can therefore be used to migrate an account of a deprecated
206+ format to the newest format or change the password for an account.
207+
208+ For non-interactive use the passphrase can be specified with the --password flag:
209+
210+ ethereum --password <passwordfile> account new
211+
212+ Since only one password can be given, only format update can be performed,
213+ changing your password is only possible interactively.
214+
215+ Note that account update has the a side effect that the order of your accounts
216+ changes.
217+ ` ,
218+ },
192219 {
193220 Action : accountImport ,
194221 Name : "import" ,
@@ -433,27 +460,39 @@ func execJSFiles(ctx *cli.Context) {
433460 ethereum .WaitForShutdown ()
434461}
435462
436- func unlockAccount (ctx * cli.Context , am * accounts.Manager , account string , i int ) {
463+ func unlockAccount (ctx * cli.Context , am * accounts.Manager , addr string , i int ) ( addrHex , auth string ) {
437464 var err error
438465 // Load startup keys. XXX we are going to need a different format
439466
440- if ! ((len (account ) == 40 ) || (len (account ) == 42 )) { // with or without 0x
441- utils .Fatalf ("Invalid account address '%s'" , account )
467+ if ! ((len (addr ) == 40 ) || (len (addr ) == 42 )) { // with or without 0x
468+ var index int
469+ index , err = strconv .Atoi (addr )
470+ if err != nil {
471+ utils .Fatalf ("Invalid account address '%s'" , addr )
472+ }
473+
474+ addrHex , err = am .AddressByIndex (index )
475+ if err != nil {
476+ utils .Fatalf ("%v" , err )
477+ }
478+ } else {
479+ addrHex = addr
442480 }
443481 // Attempt to unlock the account 3 times
444482 attempts := 3
445483 for tries := 0 ; tries < attempts ; tries ++ {
446- msg := fmt .Sprintf ("Unlocking account %s | Attempt %d/%d" , account , tries + 1 , attempts )
447- passphrase : = getPassPhrase (ctx , msg , false , i )
448- err = am .Unlock (common .HexToAddress (account ), passphrase )
484+ msg := fmt .Sprintf ("Unlocking account %s | Attempt %d/%d" , addr , tries + 1 , attempts )
485+ auth = getPassPhrase (ctx , msg , false , i )
486+ err = am .Unlock (common .HexToAddress (addrHex ), auth )
449487 if err == nil {
450488 break
451489 }
452490 }
453491 if err != nil {
454492 utils .Fatalf ("Unlock account failed '%v'" , err )
455493 }
456- fmt .Printf ("Account '%s' unlocked.\n " , account )
494+ fmt .Printf ("Account '%s' unlocked.\n " , addr )
495+ return
457496}
458497
459498func blockRecovery (ctx * cli.Context ) {
@@ -578,6 +617,21 @@ func accountCreate(ctx *cli.Context) {
578617 fmt .Printf ("Address: %x\n " , acct )
579618}
580619
620+ func accountUpdate (ctx * cli.Context ) {
621+ am := utils .MakeAccountManager (ctx )
622+ arg := ctx .Args ().First ()
623+ if len (arg ) == 0 {
624+ utils .Fatalf ("account address or index must be given as argument" )
625+ }
626+
627+ addr , authFrom := unlockAccount (ctx , am , arg , 0 )
628+ authTo := getPassPhrase (ctx , "Please give a new password. Do not forget this password." , true , 0 )
629+ err := am .Update (common .HexToAddress (addr ), authFrom , authTo )
630+ if err != nil {
631+ utils .Fatalf ("Could not update the account: %v" , err )
632+ }
633+ }
634+
581635func importWallet (ctx * cli.Context ) {
582636 keyfile := ctx .Args ().First ()
583637 if len (keyfile ) == 0 {
0 commit comments