diff --git a/.pending/improvements/sdk/3916-Hex-encode-data-in-tx-responses b/.pending/improvements/sdk/3916-Hex-encode-data-in-tx-responses new file mode 100644 index 000000000000..b56154ce0647 --- /dev/null +++ b/.pending/improvements/sdk/3916-Hex-encode-data-in-tx-responses @@ -0,0 +1 @@ +#3916 Hex encode data in tx responses diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 0ead2f3636ea..55c773cfa1ec 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -611,7 +611,9 @@ func TestSubmitProposal(t *testing.T) { require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) + bz, err := hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -646,7 +648,9 @@ func TestDeposit(t *testing.T) { require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) + bz, err := hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -703,7 +707,9 @@ func TestVote(t *testing.T) { require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) + bz, err := hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -804,18 +810,24 @@ func TestProposalsQuery(t *testing.T) { // Addr1 proposes (and deposits) proposals #1 and #2 resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit, fees) var proposalID1 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID1) + bz, err := hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID1) tests.WaitForHeight(resultTx.Height+1, port) resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit, fees) var proposalID2 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID2) + bz, err = hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID2) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 proposes (and deposits) proposals #3 resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], halfMinDeposit, fees) var proposalID3 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID3) + bz, err = hex.DecodeString(resultTx.Data) + require.NoError(t, err) + cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID3) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 deposits on proposals #2 & #3 diff --git a/types/result.go b/types/result.go index df88acdf3805..a7b3a05cd036 100644 --- a/types/result.go +++ b/types/result.go @@ -1,6 +1,7 @@ package types import ( + "encoding/hex" "encoding/json" "fmt" "strings" @@ -67,7 +68,7 @@ type TxResponse struct { Height int64 `json:"height"` TxHash string `json:"txhash"` Code uint32 `json:"code,omitempty"` - Data []byte `json:"data,omitempty"` + Data string `json:"data,omitempty"` RawLog string `json:"raw_log,omitempty"` Logs ABCIMessageLogs `json:"logs,omitempty"` Info string `json:"info,omitempty"` @@ -90,7 +91,7 @@ func NewResponseResultTx(res *ctypes.ResultTx, tx Tx) TxResponse { TxHash: res.Hash.String(), Height: res.Height, Code: res.TxResult.Code, - Data: res.TxResult.Data, + Data: strings.ToUpper(hex.EncodeToString(res.TxResult.Data)), RawLog: res.TxResult.Log, Logs: parsedLogs, Info: res.TxResult.Info, @@ -127,7 +128,7 @@ func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { Height: res.Height, TxHash: txHash, Code: res.CheckTx.Code, - Data: res.CheckTx.Data, + Data: strings.ToUpper(hex.EncodeToString(res.CheckTx.Data)), RawLog: res.CheckTx.Log, Logs: parsedLogs, Info: res.CheckTx.Info, @@ -154,7 +155,7 @@ func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) TxResponse { Height: res.Height, TxHash: txHash, Code: res.DeliverTx.Code, - Data: res.DeliverTx.Data, + Data: strings.ToUpper(hex.EncodeToString(res.DeliverTx.Data)), RawLog: res.DeliverTx.Log, Logs: parsedLogs, Info: res.DeliverTx.Info, @@ -175,7 +176,7 @@ func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) TxResponse { return TxResponse{ Code: res.Code, - Data: res.Data.Bytes(), + Data: res.Data.String(), RawLog: res.Log, Logs: parsedLogs, TxHash: res.Hash.String(), @@ -198,8 +199,8 @@ func (r TxResponse) String() string { sb.WriteString(fmt.Sprintf(" Code: %d\n", r.Code)) } - if r.Data != nil { - sb.WriteString(fmt.Sprintf(" Data: %s\n", string(r.Data))) + if r.Data != "" { + sb.WriteString(fmt.Sprintf(" Data: %s\n", r.Data)) } if r.RawLog != "" {