Use JSON for SimulationResponse
This commit is contained in:
parent
d4d4da4a6e
commit
8bb0cfdf6f
|
@ -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":
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue