From 6d1c65b76ff1ed6a9fa68f73b8bda8fb7bc2033a Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Thu, 17 Dec 2020 00:25:50 -0800 Subject: [PATCH] client: remove redundant/repeated code 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 --- client/broadcast.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/client/broadcast.go b/client/broadcast.go index e21bc080c28..0912de81e81 100644 --- a/client/broadcast.go +++ b/client/broadcast.go @@ -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