Skip to content

Commit

Permalink
[DFI-966] added height params for VM dataset (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
g3co authored Dec 15, 2020
1 parent cf6d017 commit 84810b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 84810b2

Please sign in to comment.