From 22bdc1778b3182d3837c1d0b892afed5c46c2efa Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 12 Feb 2019 11:23:03 -0500 Subject: [PATCH] Merge PR #3264: Return an empty TxResponse when nil --- PENDING.md | 2 ++ types/result.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/PENDING.md b/PENDING.md index ddeebf733..2718e7118 100644 --- a/PENDING.md +++ b/PENDING.md @@ -54,6 +54,8 @@ BUG FIXES * Gaia * [\#3585] Fix setting the tx hash in `NewResponseFormatBroadcastTxCommit`. + * [\#3585] Return an empty `TxResponse` when Tendermint returns an empty + `ResultBroadcastTx`. * SDK * [\#3582](https://github.com/cosmos/cosmos-sdk/pull/3582) Running `make test_unit was failing due to a missing tag diff --git a/types/result.go b/types/result.go index c5dcd163a..b5de7ab47 100644 --- a/types/result.go +++ b/types/result.go @@ -55,6 +55,10 @@ type TxResponse struct { } func NewResponseResultTx(res *ctypes.ResultTx, tx Tx) TxResponse { + if res == nil { + return TxResponse{} + } + return TxResponse{ TxHash: res.Hash.String(), Height: res.Height, @@ -70,6 +74,10 @@ func NewResponseResultTx(res *ctypes.ResultTx, tx Tx) TxResponse { } func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxResponse { + if res == nil { + return TxResponse{} + } + var txHash string if res.Hash != nil { txHash = res.Hash.String() @@ -90,6 +98,10 @@ func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxR } func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) TxResponse { + if res == nil { + return TxResponse{} + } + return TxResponse{ Code: res.Code, Data: res.Data.Bytes(),