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
This commit is contained in:
Emmanuel T Odeke 2020-12-17 01:30:28 -08:00 committed by GitHub
parent 002da6183c
commit 96f89df56b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 13 deletions

View File

@ -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