Skip to content

Commit

Permalink
client: remove redundant/repeated code (#8182)
Browse files Browse the repository at this point in the history
Follows up PR #4876 which removed the return on non-nil errors
to always return a non-nil REST response regardless of error.
The checks performed seem benign and the return result is the
same.
This change uses the reverse conditional refactoring method
to gut out nesting and many conditions.
Noticed while hunting through types.ParseABCILogs.

Fixes #8181
  • Loading branch information
odeke-em authored Dec 17, 2020
1 parent 002da61 commit 96f89df
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions client/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,14 @@ func (ctx Context) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error) {
}

res, err := node.BroadcastTxCommit(context.Background(), txBytes)
if err != nil {
if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return errRes, nil
}

return sdk.NewResponseFormatBroadcastTxCommit(res), err
}

if !res.CheckTx.IsOK() {
if err == nil {
return sdk.NewResponseFormatBroadcastTxCommit(res), nil
}

if !res.DeliverTx.IsOK() {
return sdk.NewResponseFormatBroadcastTxCommit(res), nil
if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return errRes, nil
}

return sdk.NewResponseFormatBroadcastTxCommit(res), nil
return sdk.NewResponseFormatBroadcastTxCommit(res), err
}

// BroadcastTxSync broadcasts transaction bytes to a Tendermint node
Expand Down

0 comments on commit 96f89df

Please sign in to comment.