Skip to content

Commit 84810b2

Browse files
authored
[DFI-966] added height params for VM dataset (#242)
1 parent cf6d017 commit 84810b2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

x/vm/client/cli/queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/cosmos/cosmos-sdk/client/context"
11+
"github.com/cosmos/cosmos-sdk/client/flags"
1112
"github.com/cosmos/cosmos-sdk/codec"
1213
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
1314
"github.com/dfinance/dvm-proto/go/compiler_grpc"
@@ -29,6 +30,11 @@ func GetData(queryRoute string, cdc *codec.Codec) *cobra.Command {
2930
Args: cobra.ExactArgs(2),
3031
RunE: func(cmd *cobra.Command, args []string) error {
3132
cliCtx := context.NewCLIContext().WithCodec(cdc)
33+
height := viper.GetInt64(flags.FlagHeight)
34+
35+
if height != 0 {
36+
cliCtx = cliCtx.WithHeight(height)
37+
}
3238

3339
// parse inputs
3440
address, err := helpers.ParseSdkAddressParam("address", args[0], helpers.ParamTypeCliArg)

x/vm/client/rest/rest.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc {
139139
// parse inputs and prepare request
140140
vars := mux.Vars(r)
141141

142+
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
143+
if !ok {
144+
return
145+
}
146+
142147
address, err := helpers.ParseSdkAddressParam(accountAddrName, vars[accountAddrName], helpers.ParamTypeRestPath)
143148
if err != nil {
144149
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request")
@@ -155,19 +160,24 @@ func getData(cliCtx context.CLIContext) http.HandlerFunc {
155160
Address: common_vm.Bech32ToLibra(address),
156161
Path: path,
157162
})
163+
158164
if err != nil {
159165
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
160166
return
161167
}
162168

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

177+
if cliCtx.Height == 0 {
178+
cliCtx = context.NewCLIContext().WithCodec(cliCtx.Codec).WithHeight(height)
179+
}
180+
171181
rest.PostProcessResponse(w, cliCtx, resp)
172182
}
173183
}

0 commit comments

Comments
 (0)