switch GetConfirmation()'s default to no (#4575)

client/input.GetConfirmation() returns true if and only if the
user's input is confirmative.

The function is used in places where fat-fingering may cause
financial loss, e.g. gaiacli tx send command. Thus it seems
wiser to provide a conservative default in order to protect
users from accidental mistyping.

Closes: #4564
This commit is contained in:
Alessio Treglia 2019-06-18 11:46:51 +02:00 committed by GitHub
parent 36142ab624
commit 1fcac93d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -1 +1 @@
#4564 Allow empty answer to evaluate as 'Y' on tx submission prompt.
#4564 client/input.GetConfirmation()'s default is changed to No.

View File

@ -85,11 +85,11 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error)
// GetConfirmation will request user give the confirmation from stdin.
// "y", "Y", "yes", "YES", and "Yes" all count as confirmations.
// If the input is not recognized, it will ask again.
// If the input is not recognized, it returns false and a nil error.
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
for {
if inputIsTty() {
fmt.Print(fmt.Sprintf("%s [Y/n]: ", prompt))
fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
}
response, err := readLineFromBuf(buf)
@ -98,11 +98,11 @@ func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
}
response = strings.ToLower(strings.TrimSpace(response))
if response == "y" || response == "yes" || response == "" {
if response[0] == 'y' {
return true, nil
} else if response == "n" || response == "no" {
return false, nil
}
return false, nil
}
}

View File

@ -110,10 +110,13 @@ func runAddCmd(_ *cobra.Command, args []string) error {
_, err = kb.Get(name)
if err == nil {
// account exists, ask for user confirmation
if response, err2 := input.GetConfirmation(
fmt.Sprintf("override the existing name %s", name), buf); err2 != nil || !response {
response, err2 := input.GetConfirmation(fmt.Sprintf("override the existing name %s", name), buf)
if err2 != nil {
return err2
}
if !response {
return errors.New("aborted")
}
}
multisigKeys := viper.GetStringSlice(flagMultisig)