58
58
gitCommit string // set via linker flagg
59
59
nodeNameVersion string
60
60
app * cli.App
61
-
62
- ExtraDataFlag = cli.StringFlag {
63
- Name : "extradata" ,
64
- Usage : "Extra data for the miner" ,
65
- }
66
61
)
67
62
68
63
func init () {
@@ -176,8 +171,12 @@ It is safe to transfer the entire directory or the individual keys therein
176
171
between ethereum nodes by simply copying.
177
172
Make sure you backup your keys regularly.
178
173
179
- In order to use your account to send transactions, you need to unlock them using the
180
- '--unlock' option. The argument is a comma
174
+ In order to use your account to send transactions, you need to unlock them using
175
+ the '--unlock' option. The argument is a space separated list of addresses or
176
+ indexes. If used non-interactively with a passwordfile, the file should contain
177
+ the respective passwords one per line. If you unlock n accounts and the password
178
+ file contains less than n entries, then the last password is meant to apply to
179
+ all remaining accounts.
181
180
182
181
And finally. DO NOT FORGET YOUR PASSWORD.
183
182
` ,
@@ -227,7 +226,7 @@ format to the newest format or change the password for an account.
227
226
228
227
For non-interactive use the passphrase can be specified with the --password flag:
229
228
230
- ethereum --password <passwordfile> account new
229
+ ethereum --password <passwordfile> account update <address>
231
230
232
231
Since only one password can be given, only format update can be performed,
233
232
changing your password is only possible interactively.
@@ -354,7 +353,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
354
353
utils .GpobaseStepDownFlag ,
355
354
utils .GpobaseStepUpFlag ,
356
355
utils .GpobaseCorrectionFactorFlag ,
357
- ExtraDataFlag ,
356
+ utils . ExtraDataFlag ,
358
357
}
359
358
app .Before = func (ctx * cli.Context ) error {
360
359
utils .SetupLogger (ctx )
@@ -380,8 +379,8 @@ func main() {
380
379
381
380
// makeExtra resolves extradata for the miner from a flag or returns a default.
382
381
func makeExtra (ctx * cli.Context ) []byte {
383
- if ctx .GlobalIsSet (ExtraDataFlag .Name ) {
384
- return []byte (ctx .GlobalString (ExtraDataFlag .Name ))
382
+ if ctx .GlobalIsSet (utils . ExtraDataFlag .Name ) {
383
+ return []byte (ctx .GlobalString (utils . ExtraDataFlag .Name ))
385
384
}
386
385
return makeDefaultExtra ()
387
386
}
@@ -517,28 +516,29 @@ func execJSFiles(ctx *cli.Context) {
517
516
ethereum .WaitForShutdown ()
518
517
}
519
518
520
- func unlockAccount (ctx * cli.Context , am * accounts.Manager , addr string , i int ) (addrHex , auth string ) {
521
- utils .CheckLegalese (utils . MustDataDir ( ctx ))
519
+ func unlockAccount (ctx * cli.Context , am * accounts.Manager , addr string , i int , inputpassphrases [] string ) (addrHex , auth string , passphrases [] string ) {
520
+ utils .CheckLegalese (ctx . GlobalString ( utils . DataDirFlag . Name ))
522
521
523
522
var err error
523
+ passphrases = inputpassphrases
524
524
addrHex , err = utils .ParamToAddress (addr , am )
525
525
if err == nil {
526
526
// Attempt to unlock the account 3 times
527
527
attempts := 3
528
528
for tries := 0 ; tries < attempts ; tries ++ {
529
529
msg := fmt .Sprintf ("Unlocking account %s | Attempt %d/%d" , addr , tries + 1 , attempts )
530
- auth = getPassPhrase (ctx , msg , false , i )
530
+ auth , passphrases = getPassPhrase (ctx , msg , false , i , passphrases )
531
531
err = am .Unlock (common .HexToAddress (addrHex ), auth )
532
- if err == nil {
532
+ if err == nil || passphrases != nil {
533
533
break
534
534
}
535
535
}
536
536
}
537
537
538
538
if err != nil {
539
- utils .Fatalf ("Unlock account failed '%v'" , err )
539
+ utils .Fatalf ("Unlock account '%s' (%v) failed: %v" , addr , addrHex , err )
540
540
}
541
- fmt .Printf ("Account '%s' unlocked.\n " , addr )
541
+ fmt .Printf ("Account '%s' (%v) unlocked.\n " , addr , addrHex )
542
542
return
543
543
}
544
544
@@ -582,12 +582,13 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
582
582
am := eth .AccountManager ()
583
583
account := ctx .GlobalString (utils .UnlockedAccountFlag .Name )
584
584
accounts := strings .Split (account , " " )
585
+ var passphrases []string
585
586
for i , account := range accounts {
586
587
if len (account ) > 0 {
587
588
if account == "primary" {
588
589
utils .Fatalf ("the 'primary' keyword is deprecated. You can use integer 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." )
589
590
}
590
- unlockAccount (ctx , am , account , i )
591
+ _ , _ , passphrases = unlockAccount (ctx , am , account , i , passphrases )
591
592
}
592
593
}
593
594
// Start auxiliary services if enabled.
@@ -624,7 +625,7 @@ func accountList(ctx *cli.Context) {
624
625
}
625
626
}
626
627
627
- func getPassPhrase (ctx * cli.Context , desc string , confirmation bool , i int ) (passphrase string ) {
628
+ func getPassPhrase (ctx * cli.Context , desc string , confirmation bool , i int , inputpassphrases [] string ) (passphrase string , passphrases [] string ) {
628
629
passfile := ctx .GlobalString (utils .PasswordFileFlag .Name )
629
630
if len (passfile ) == 0 {
630
631
fmt .Println (desc )
@@ -644,14 +645,17 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool, i int) (pas
644
645
passphrase = auth
645
646
646
647
} else {
647
- passbytes , err := ioutil .ReadFile (passfile )
648
- if err != nil {
649
- utils .Fatalf ("Unable to read password file '%s': %v" , passfile , err )
648
+ passphrases = inputpassphrases
649
+ if passphrases == nil {
650
+ passbytes , err := ioutil .ReadFile (passfile )
651
+ if err != nil {
652
+ utils .Fatalf ("Unable to read password file '%s': %v" , passfile , err )
653
+ }
654
+ // this is backwards compatible if the same password unlocks several accounts
655
+ // it also has the consequence that trailing newlines will not count as part
656
+ // of the password, so --password <(echo -n 'pass') will now work without -n
657
+ passphrases = strings .Split (string (passbytes ), "\n " )
650
658
}
651
- // this is backwards compatible if the same password unlocks several accounts
652
- // it also has the consequence that trailing newlines will not count as part
653
- // of the password, so --password <(echo -n 'pass') will now work without -n
654
- passphrases := strings .Split (string (passbytes ), "\n " )
655
659
if i >= len (passphrases ) {
656
660
passphrase = passphrases [len (passphrases )- 1 ]
657
661
} else {
@@ -665,7 +669,7 @@ func accountCreate(ctx *cli.Context) {
665
669
utils .CheckLegalese (utils .MustDataDir (ctx ))
666
670
667
671
am := utils .MakeAccountManager (ctx )
668
- passphrase := getPassPhrase (ctx , "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 )
672
+ passphrase , _ := getPassPhrase (ctx , "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 , nil )
669
673
acct , err := am .NewAccount (passphrase )
670
674
if err != nil {
671
675
utils .Fatalf ("Could not create the account: %v" , err )
@@ -682,8 +686,8 @@ func accountUpdate(ctx *cli.Context) {
682
686
utils .Fatalf ("account address or index must be given as argument" )
683
687
}
684
688
685
- addr , authFrom := unlockAccount (ctx , am , arg , 0 )
686
- authTo := getPassPhrase (ctx , "Please give a new password. Do not forget this password." , true , 0 )
689
+ addr , authFrom , passphrases := unlockAccount (ctx , am , arg , 0 , nil )
690
+ authTo , _ := getPassPhrase (ctx , "Please give a new password. Do not forget this password." , true , 0 , passphrases )
687
691
err := am .Update (common .HexToAddress (addr ), authFrom , authTo )
688
692
if err != nil {
689
693
utils .Fatalf ("Could not update the account: %v" , err )
@@ -703,7 +707,7 @@ func importWallet(ctx *cli.Context) {
703
707
}
704
708
705
709
am := utils .MakeAccountManager (ctx )
706
- passphrase := getPassPhrase (ctx , "" , false , 0 )
710
+ passphrase , _ := getPassPhrase (ctx , "" , false , 0 , nil )
707
711
708
712
acct , err := am .ImportPreSaleKey (keyJson , passphrase )
709
713
if err != nil {
@@ -720,7 +724,7 @@ func accountImport(ctx *cli.Context) {
720
724
utils .Fatalf ("keyfile must be given as argument" )
721
725
}
722
726
am := utils .MakeAccountManager (ctx )
723
- passphrase := getPassPhrase (ctx , "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 )
727
+ passphrase , _ := getPassPhrase (ctx , "Your new account is locked with a password. Please give a password. Do not forget this password." , true , 0 , nil )
724
728
acct , err := am .Import (keyfile , passphrase )
725
729
if err != nil {
726
730
utils .Fatalf ("Could not create the account: %v" , err )
0 commit comments