-
Notifications
You must be signed in to change notification settings - Fork 568
/
query.go
62 lines (49 loc) · 1.5 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package rest
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/c-osmosis/osmosis/x/mint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/types/rest"
)
func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
r.HandleFunc(
"/minting/parameters",
queryParamsHandlerFn(clientCtx),
).Methods("GET")
r.HandleFunc(
"/minting/epoch-provisions",
queryEpochProvisionsHandlerFn(clientCtx),
).Methods("GET")
}
func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters)
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
}
res, height, err := clientCtx.QueryWithData(route, nil)
if rest.CheckInternalServerError(w, err) {
return
}
clientCtx = clientCtx.WithHeight(height)
rest.PostProcessResponse(w, clientCtx, res)
}
}
func queryEpochProvisionsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryEpochProvisions)
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
}
res, height, err := clientCtx.QueryWithData(route, nil)
if rest.CheckInternalServerError(w, err) {
return
}
clientCtx = clientCtx.WithHeight(height)
rest.PostProcessResponse(w, clientCtx, res)
}
}