diff --git a/client/context/broadcast.go b/client/context/broadcast.go index c844e519d120..8be256b53aac 100644 --- a/client/context/broadcast.go +++ b/client/context/broadcast.go @@ -131,6 +131,16 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast return res, err } + if ctx.TxResponseHandler != nil { + err = ctx.TxResponseHandler(res) + } else { + err = ctx.DefaultTxResponseHandler(res) + } + return res, err + +} + +func (ctx CLIContext) DefaultTxResponseHandler(res *ctypes.ResultBroadcastTxCommit) error { if ctx.OutputFormat == "json" { // Since JSON is intended for automated scripts, always include response in // JSON mode. @@ -144,14 +154,14 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast resJSON := toJSON{res.Height, res.Hash.String(), res.DeliverTx} bz, err := ctx.Codec.MarshalJSON(resJSON) if err != nil { - return res, err + return err } ctx.Output.Write(bz) io.WriteString(ctx.Output, "\n") } - return res, nil + return nil } if ctx.Output != nil { @@ -166,5 +176,5 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast io.WriteString(ctx.Output, resStr) } - return res, nil + return nil } diff --git a/client/context/context.go b/client/context/context.go index a253a88fae55..709f0c7a5c09 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -20,6 +20,7 @@ import ( tmlite "github.com/tendermint/tendermint/lite" tmliteProxy "github.com/tendermint/tendermint/lite/proxy" rpcclient "github.com/tendermint/tendermint/rpc/client" + ctypes "github.com/tendermint/tendermint/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -42,12 +43,14 @@ type CLIContext struct { UseLedger bool Async bool PrintResponse bool - Verifier tmlite.Verifier - Simulate bool - GenerateOnly bool - FromAddress sdk.AccAddress - FromName string - Indent bool + // Overrides the default CLI transaction response handling with a custom handler + TxResponseHandler func(res *ctypes.ResultBroadcastTxCommit) error + Verifier tmlite.Verifier + Simulate bool + GenerateOnly bool + FromAddress sdk.AccAddress + FromName string + Indent bool } // NewCLIContext returns a new initialized CLIContext with parameters from the