From 8bb2569abc523c80ff55011276ee7745a30cb7ca Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Mon, 6 May 2019 22:53:12 +0800 Subject: [PATCH] R4R: Fix /txs/encode endpoint (#4212) Closes: #4141 --- .pending/improvements/gaiarest/4141-Fix-txs-encode- | 1 + client/tx/encode.go | 8 +++----- cmd/gaia/lcd_test/lcd_test.go | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) create mode 100644 .pending/improvements/gaiarest/4141-Fix-txs-encode- diff --git a/.pending/improvements/gaiarest/4141-Fix-txs-encode- b/.pending/improvements/gaiarest/4141-Fix-txs-encode- new file mode 100644 index 000000000000..0c19a162428b --- /dev/null +++ b/.pending/improvements/gaiarest/4141-Fix-txs-encode- @@ -0,0 +1 @@ +#4141 Fix /txs/encode endpoint \ No newline at end of file diff --git a/client/tx/encode.go b/client/tx/encode.go index 5ea64ea720cc..77cf323b2555 100644 --- a/client/tx/encode.go +++ b/client/tx/encode.go @@ -18,9 +18,7 @@ import ( type ( // EncodeReq defines a tx encoding request. - EncodeReq struct { - Tx auth.StdTx `json:"tx"` - } + // Use auth.StdTx directly // EncodeResp defines a tx encoding response. EncodeResp struct { @@ -33,7 +31,7 @@ type ( // and responds with base64-encoded bytes. func EncodeTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req EncodeReq + var req auth.StdTx body, err := ioutil.ReadAll(r.Body) if err != nil { @@ -48,7 +46,7 @@ func EncodeTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http. } // re-encode it via the Amino wire protocol - txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(req.Tx) + txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(req) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/cmd/gaia/lcd_test/lcd_test.go b/cmd/gaia/lcd_test/lcd_test.go index 8cf7d5d6eb4b..d7693cf8c70f 100644 --- a/cmd/gaia/lcd_test/lcd_test.go +++ b/cmd/gaia/lcd_test/lcd_test.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" - clienttx "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/crypto/keys/mintkey" "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" @@ -291,10 +290,9 @@ func TestEncodeTx(t *testing.T) { res, body, _ := doTransferWithGas(t, port, seed, name1, memo, "", addr, "2", 1, false, false, fees) var tx auth.StdTx - cdc.UnmarshalJSON([]byte(body), &tx) + require.Nil(t, cdc.UnmarshalJSON([]byte(body), &tx)) - req := clienttx.EncodeReq{Tx: tx} - encodedJSON, _ := cdc.MarshalJSON(req) + encodedJSON, _ := cdc.MarshalJSON(tx) res, body = Request(t, port, "POST", "/txs/encode", encodedJSON) // Make sure it came back ok, and that we can decode it back to the transaction