From 96f89df56be446984ff85fea84326a5555b3085e Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Thu, 17 Dec 2020 01:30:28 -0800 Subject: [PATCH] client: remove redundant/repeated code (#8182) 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 e21bc080c2..0912de81e8 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