Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions x/vm/client/cli/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/dfinance/dvm-proto/go/compiler_grpc"
Expand All @@ -29,6 +30,11 @@ func GetData(queryRoute string, cdc *codec.Codec) *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
height := viper.GetInt64(flags.FlagHeight)

if height != 0 {
cliCtx = cliCtx.WithHeight(height)
}

// parse inputs
address, err := helpers.ParseSdkAddressParam("address", args[0], helpers.ParamTypeCliArg)
Expand Down
12 changes: 11 additions & 1 deletion x/vm/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc {
// parse inputs and prepare request
vars := mux.Vars(r)

cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

address, err := helpers.ParseSdkAddressParam(accountAddrName, vars[accountAddrName], helpers.ParamTypeRestPath)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request")
Expand All @@ -155,19 +160,24 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc {
Address: common_vm.Bech32ToLibra(address),
Path: path,
})

if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

// send request and process response
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryValue), bz)
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryValue), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
resp := types.ValueResp{Value: hex.EncodeToString(res)}

if cliCtx.Height == 0 {
cliCtx = context.NewCLIContext().WithCodec(cliCtx.Codec).WithHeight(height)
}

rest.PostProcessResponse(w, cliCtx, resp)
}
}
Expand Down