parent
b922d3c58b
commit
8bb2569abc
1
.pending/improvements/gaiarest/4141-Fix-txs-encode-
Normal file
1
.pending/improvements/gaiarest/4141-Fix-txs-encode-
Normal file
@ -0,0 +1 @@
|
||||
#4141 Fix /txs/encode endpoint
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user