From 8bb0cfdf6f5f6d6147edb8d42f4594b1b618bd84 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Tue, 24 Mar 2020 16:45:34 -0400 Subject: [PATCH] Use JSON for SimulationResponse --- baseapp/abci.go | 9 +++++++-- client/tx/tx.go | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index e984fe0edf..3342f1aebc 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -1,6 +1,7 @@ package baseapp import ( + "encoding/json" "fmt" "os" "sort" @@ -9,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -336,10 +336,15 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res Result: res, } + bz, err := json.Marshal(simRes) + if err != nil { + return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to JSON encode simulation response")) + } + return abci.ResponseQuery{ Codespace: sdkerrors.RootCodespace, Height: req.Height, - Value: codec.Cdc.MustMarshalBinaryBare(simRes), + Value: bz, } case "version": diff --git a/client/tx/tx.go b/client/tx/tx.go index 49dfb1cddf..638c7eeec6 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -2,6 +2,7 @@ package tx import ( "bufio" + "encoding/json" "errors" "fmt" "os" @@ -216,14 +217,13 @@ func CalculateGas( queryFunc func(string, []byte) ([]byte, int64, error), txBytes []byte, adjustment float64, ) (sdk.SimulationResponse, uint64, error) { - rawRes, _, err := queryFunc("/app/simulate", txBytes) + bz, _, err := queryFunc("/app/simulate", txBytes) if err != nil { return sdk.SimulationResponse{}, 0, err } - // TODO: Use JSON or proto instead of codec.cdc var simRes sdk.SimulationResponse - if err := codec.Cdc.UnmarshalBinaryBare(rawRes, &simRes); err != nil { + if err := json.Unmarshal(bz, &simRes); err != nil { return sdk.SimulationResponse{}, 0, err }