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 4 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
4 changes: 4 additions & 0 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast
return res, err
}

if ctx.ResponseHandler != nil {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is a flexible way of doing this. May I suggest a few things?

  • Rename ResponseHandler to TxResponseHandler to provide better context
  • Take the two if statements below this and stuff them into a DefaultTxResponseHandler. This will DRY and cleanup broadcastTxCommit.
  • Perhaps implement another TxResponseHandler that pretty prints the response (this may require merging @sunnya97's PR).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Rename ResponseHandler to TxResponseHandler to provide better context
  • Take the two if statements below this and stuff them into a DefaultTxResponseHandler. This will DRY and cleanup broadcastTxCommit.

Okay, pushed these two changes. I added error as the return to TxResponseHandler because MarshalJSON could return an error in DefaultTxResponseHandler. Looks like the error is handled higher up. I agree this is nice for DRY because it would allow someone to just wrap the default functionality.

  • Perhaps implement another TxResponseHandler that pretty prints the response (this may require merging @sunnya97's PR).

Happy to help with that. Is it okay if it's in a separate PR connected with the discussion in #2953 ?

return ctx.ResponseHandler(res)
}

if ctx.OutputFormat == "json" {
// Since JSON is intended for automated scripts, always include response in
// JSON mode.
Expand Down
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
ResponseHandler func(res *ctypes.ResultBroadcastTxCommit) (*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