Merge PR #3698: Prompt User Confirmation Prior to Signing & Broadcasting
* Prompt user confirmation prior to sign & broadcasting * Update confirmation message * Update and fix existing CLI integration tests * Implement CLI integration test for tx confirmation * Fix order of input into tx send
This commit is contained in:
committed by
Christopher Goes
parent
250dc9807b
commit
feb98bcd05
@@ -53,6 +53,7 @@ type CLIContext struct {
|
||||
FromAddress sdk.AccAddress
|
||||
FromName string
|
||||
Indent bool
|
||||
SkipConfirm bool
|
||||
}
|
||||
|
||||
// NewCLIContext returns a new initialized CLIContext with parameters from the
|
||||
@@ -96,6 +97,7 @@ func NewCLIContext() CLIContext {
|
||||
FromAddress: fromAddress,
|
||||
FromName: fromName,
|
||||
Indent: viper.GetBool(client.FlagIndentResponse),
|
||||
SkipConfirm: viper.GetBool(client.FlagSkipConfirmation),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -45,6 +45,7 @@ const (
|
||||
FlagSSLCertFile = "ssl-certfile"
|
||||
FlagSSLKeyFile = "ssl-keyfile"
|
||||
FlagOutputDocument = "output-document" // inspired by wget -O
|
||||
FlagSkipConfirmation = "yes"
|
||||
)
|
||||
|
||||
// LineBreak can be included in a command list to provide a blank line
|
||||
@@ -89,9 +90,14 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
|
||||
c.Flags().Bool(FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)")
|
||||
c.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it")
|
||||
c.Flags().Bool(FlagGenerateOnly, false, "build an unsigned transaction and write it to STDOUT")
|
||||
c.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation")
|
||||
|
||||
// --gas can accept integers and "simulate"
|
||||
c.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf(
|
||||
"gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)", GasFlagAuto, DefaultGasLimit))
|
||||
"gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
|
||||
GasFlagAuto, DefaultGasLimit,
|
||||
))
|
||||
|
||||
viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode))
|
||||
viper.BindPFlag(FlagUseLedger, c.Flags().Lookup(FlagUseLedger))
|
||||
viper.BindPFlag(FlagNode, c.Flags().Lookup(FlagNode))
|
||||
|
||||
+3
-2
@@ -9,7 +9,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/bgentry/speakeasy"
|
||||
"github.com/mattn/go-isatty"
|
||||
isatty "github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
// MinPassLength is the minimum acceptable password length
|
||||
@@ -90,8 +90,9 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, 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)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -62,6 +62,22 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
|
||||
return nil
|
||||
}
|
||||
|
||||
if !cliCtx.SkipConfirm {
|
||||
stdSignMsg, err := txBldr.BuildSignMsg(msgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "%s\n\n", cliCtx.Codec.MustMarshalJSON(stdSignMsg))
|
||||
|
||||
buf := client.BufferStdin()
|
||||
ok, err := client.GetConfirmation("confirm transaction before signing and broadcasting", buf)
|
||||
if err != nil || !ok {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", "cancelled transaction")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
passphrase, err := keys.GetPassphrase(fromName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user