Skip to content

Commit

Permalink
R4R: Fix /txs/encode endpoint (#4212)
Browse files Browse the repository at this point in the history
Closes: #4141
  • Loading branch information
Frank Yang authored and Alessio Treglia committed May 6, 2019
1 parent b922d3c commit 8bb2569
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions .pending/improvements/gaiarest/4141-Fix-txs-encode-
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4141 Fix /txs/encode endpoint
8 changes: 3 additions & 5 deletions client/tx/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions cmd/gaia/lcd_test/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8bb2569

Please sign in to comment.