[wallet] support --pass in wallet new command

This is to enable batch creation of new accounts w/o manual passphrase
input.

Todo: this option support can be added to other commands, like balances, transfer.

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1086/head
Leo Chen 6 years ago
parent d129a1cef1
commit 79e7c02649
  1. 21
      cmd/client/wallet/main.go

@ -63,6 +63,10 @@ var (
// New subcommands // New subcommands
newCommand = flag.NewFlagSet("new", flag.ExitOnError) newCommand = flag.NewFlagSet("new", flag.ExitOnError)
newCommandNoPassPtr = newCommand.Bool("nopass", false, "The account has no pass phrase") newCommandNoPassPtr = newCommand.Bool("nopass", false, "The account has no pass phrase")
// -pass takes on "pass:password", "env:var", "file:pathname",
// "fd:number", or "stdin" form.
// See “PASS PHRASE ARGUMENTS” section of openssl(1) for details.
newCommandPassPtr = newCommand.String("pass", "", "how to get passphrase for the key")
// List subcommands // List subcommands
listCommand = flag.NewFlagSet("list", flag.ExitOnError) listCommand = flag.NewFlagSet("list", flag.ExitOnError)
@ -128,6 +132,7 @@ func main() {
fmt.Println("Actions:") fmt.Println("Actions:")
fmt.Println(" 1. new - Generates a new account and store the private key locally") fmt.Println(" 1. new - Generates a new account and store the private key locally")
fmt.Println(" --nopass - The private key has no passphrase (for test only)") fmt.Println(" --nopass - The private key has no passphrase (for test only)")
fmt.Println(" --pass - The passphrase for the private key, in the format of: pass:password, env:var, file:pathname, fd:number, or stdin")
fmt.Println(" 2. list - Lists all accounts in local keystore") fmt.Println(" 2. list - Lists all accounts in local keystore")
fmt.Println(" 3. removeAll - Removes all accounts in local keystore") fmt.Println(" 3. removeAll - Removes all accounts in local keystore")
fmt.Println(" 4. import - Imports a new account by private key") fmt.Println(" 4. import - Imports a new account by private key")
@ -277,14 +282,22 @@ func processNewCommnad() {
return return
} }
noPass := *newCommandNoPassPtr noPass := *newCommandNoPassPtr
pass := *newCommandPassPtr
password := "" password := ""
if !noPass { if !noPass {
password = utils.AskForPassphrase("Passphrase: ") if pass == "" {
password2 := utils.AskForPassphrase("Passphrase again: ") password = utils.AskForPassphrase("Passphrase: ")
if password != password2 { password2 := utils.AskForPassphrase("Passphrase again: ")
fmt.Printf("Passphrase doesn't match. Please try again!\n") if password != password2 {
fmt.Printf("Passphrase doesn't match. Please try again!\n")
os.Exit(3)
}
} else if newPass, err := utils.GetPassphraseFromSource(pass); err != nil {
fmt.Printf("Cannot read passphrase: %s\n", err)
os.Exit(3) os.Exit(3)
} else {
password = newPass
} }
} }

Loading…
Cancel
Save