mirror of https://github.com/certusone/wasmd.git
Use height from query and return height on query
This commit is contained in:
parent
2b1972ace3
commit
eeb12592f3
|
@ -29,12 +29,18 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
|||
|
||||
func listCodesHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, keeper.QueryListCode)
|
||||
res, _, err := cliCtx.Query(route)
|
||||
res, height, err := cliCtx.Query(route)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, string(res))
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +53,13 @@ func queryCodeHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%d", types.QuerierRoute, keeper.QueryGetCode, codeID)
|
||||
res, _, err := cliCtx.Query(route)
|
||||
res, height, err := cliCtx.Query(route)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -70,6 +81,7 @@ func queryCodeHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, code)
|
||||
}
|
||||
}
|
||||
|
@ -81,12 +93,19 @@ func listContractsByCodeHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%d", types.QuerierRoute, keeper.QueryListContractByCode, codeID)
|
||||
res, _, err := cliCtx.Query(route)
|
||||
res, height, err := cliCtx.Query(route)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, string(res))
|
||||
}
|
||||
}
|
||||
|
@ -98,13 +117,19 @@ func queryContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContract, addr.String())
|
||||
res, _, err := cliCtx.Query(route)
|
||||
res, height, err := cliCtx.Query(route)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, string(res))
|
||||
}
|
||||
}
|
||||
|
@ -116,9 +141,13 @@ func queryContractStateAllHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateAll)
|
||||
res, _, err := cliCtx.Query(route)
|
||||
res, height, err := cliCtx.Query(route)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -131,6 +160,8 @@ func queryContractStateAllHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, resultData)
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +180,13 @@ func queryContractStateRawHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateRaw)
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
res, _, err := cliCtx.QueryWithData(route, queryData)
|
||||
route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateRaw)
|
||||
res, height, err := cliCtx.QueryWithData(route, queryData)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -163,6 +198,8 @@ func queryContractStateRawHandlerFn(cliCtx context.CLIContext) http.HandlerFunc
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, resultData)
|
||||
}
|
||||
}
|
||||
|
@ -174,13 +211,16 @@ type smartResponse struct {
|
|||
func queryContractStateSmartHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
decoder := newArgDecoder(hex.DecodeString)
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(mux.Vars(r)["contractAddr"])
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
decoder.encoding = mux.Vars(r)["encoding"]
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateSmart)
|
||||
|
||||
|
@ -189,13 +229,15 @@ func queryContractStateSmartHandlerFn(cliCtx context.CLIContext) http.HandlerFun
|
|||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
res, _, err := cliCtx.QueryWithData(route, queryData)
|
||||
res, height, err := cliCtx.QueryWithData(route, queryData)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
// return as raw bytes (to be base64-encoded)
|
||||
responseData := smartResponse{Smart: res}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
rest.PostProcessResponse(w, cliCtx, responseData)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue