Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Allow overriding of CLI transaction response handling #3276

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -166,5 +176,5 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast
io.WriteString(ctx.Output, resStr)
}

return res, nil
return nil
}
15 changes: 9 additions & 6 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand Down