/
rest.go
34 lines (27 loc) · 1.05 KB
/
rest.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
package rest
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/coinexchain/cet-sdk/modules/stakingx/internal/types"
"github.com/coinexchain/cosmos-utils/client/restutil"
)
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/staking/pool", poolHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/staking/parameters", paramsHandlerFn(cliCtx)).Methods("GET")
}
// HTTP request handler to query the pool information
func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
restutil.RestQuery(nil, cliCtx, w, r, "custom/stakingx/pool", nil, nil)
}
}
// HTTP request handler to query the staking params values
func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.StoreKey, staking.QueryParameters)
restutil.RestQuery(nil, cliCtx, w, r, route, nil, nil)
}
}