fix: client/tx: improve user experience on errors in BroadcastTx (#14254)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
Emmanuel T Odeke 2022-12-16 09:00:05 -07:00 committed by GitHub
parent b81f385cc5
commit 65b4fbc170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,16 +94,19 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
}
if err := clientCtx.PrintRaw(json.RawMessage(txBytes)); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%s\n", txBytes)
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes)
}
buf := bufio.NewReader(os.Stdin)
ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr)
if err != nil || !ok {
_, _ = fmt.Fprintf(os.Stderr, "%s\n", "cancelled transaction")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "error: %v\ncancelled transaction\n", err)
return err
}
if !ok {
_, _ = fmt.Fprintln(os.Stderr, "cancelled transaction")
return nil
}
}
// When Textual is wired up, the context argument should be retrieved from the client context.