prompt: minror refactoring
This commit is contained in:
parent
92acdcbfca
commit
d9d257a9f6
2 changed files with 11 additions and 48 deletions
|
@ -22,8 +22,12 @@ import (
|
||||||
|
|
||||||
// ProvideSeed is used to prompt for the wallet seed which maybe required during
|
// ProvideSeed is used to prompt for the wallet seed which maybe required during
|
||||||
// upgrades.
|
// upgrades.
|
||||||
func ProvideSeed() ([]byte, error) {
|
func ProvideSeed() func() ([]byte, error) {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
return func() ([]byte, error) {
|
||||||
|
return provideSeed(bufio.NewReader(os.Stdin))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func provideSeed(reader *bufio.Reader) ([]byte, error) {
|
||||||
for {
|
for {
|
||||||
fmt.Print("Enter existing wallet seed: ")
|
fmt.Print("Enter existing wallet seed: ")
|
||||||
seedStr, err := reader.ReadString('\n')
|
seedStr, err := reader.ReadString('\n')
|
||||||
|
@ -229,30 +233,9 @@ func PublicPass(reader *bufio.Reader, privPass []byte,
|
||||||
return configPubPassphrase, nil
|
return configPubPassphrase, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pubPass, err = provideSeed(reader)
|
||||||
for {
|
if err != nil {
|
||||||
pubPass, err = promptPass(reader, "Enter the public "+
|
return nil, err
|
||||||
"passphrase for your new wallet", true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if bytes.Equal(pubPass, privPass) {
|
|
||||||
useSamePass, err := promptListBool(reader,
|
|
||||||
"Are you sure want to use the same passphrase "+
|
|
||||||
"for public and private data?", "no")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if useSamePass {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("NOTE: Use the --walletpass option to configure your " +
|
fmt.Println("NOTE: Use the --walletpass option to configure your " +
|
||||||
|
@ -304,25 +287,5 @@ func Seed(reader *bufio.Reader) ([]byte, error) {
|
||||||
return seed, nil
|
return seed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
return provideSeed(reader)
|
||||||
fmt.Print("Enter existing wallet seed: ")
|
|
||||||
seedStr, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
seedStr = strings.TrimSpace(strings.ToLower(seedStr))
|
|
||||||
|
|
||||||
seed, err := hex.DecodeString(seedStr)
|
|
||||||
if err != nil || len(seed) < hdkeychain.MinSeedBytes ||
|
|
||||||
len(seed) > hdkeychain.MaxSeedBytes {
|
|
||||||
|
|
||||||
fmt.Printf("Invalid seed specified. Must be a "+
|
|
||||||
"hexadecimal value that is at least %d bits and "+
|
|
||||||
"at most %d bits\n", hdkeychain.MinSeedBytes*8,
|
|
||||||
hdkeychain.MaxSeedBytes*8)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return seed, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool)
|
||||||
var cbs *waddrmgr.OpenCallbacks
|
var cbs *waddrmgr.OpenCallbacks
|
||||||
if canConsolePrompt {
|
if canConsolePrompt {
|
||||||
cbs = &waddrmgr.OpenCallbacks{
|
cbs = &waddrmgr.OpenCallbacks{
|
||||||
ObtainSeed: prompt.ProvideSeed,
|
ObtainSeed: prompt.ProvideSeed(),
|
||||||
ObtainPrivatePass: prompt.ProvidePrivPassphrase,
|
ObtainPrivatePass: prompt.ProvidePrivPassphrase,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue