forked from bandprotocol/bandchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
40 lines (37 loc) · 1.25 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
package rest
import (
"fmt"
"github.com/GeoDB-Limited/odincore/chain/x/coinswap/types"
commonrest "github.com/GeoDB-Limited/odincore/chain/x/common/client/rest"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"net/http"
)
func getParamsHandler(cliCtx context.CLIContext, route string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
bz, height, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", route, types.QueryParams))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
commonrest.PostProcessQueryResponse(w, cliCtx.WithHeight(height), bz)
}
}
func getRateHandler(cliCtx context.CLIContext, route string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
bz, height, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", route, types.QueryRate))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
commonrest.PostProcessQueryResponse(w, cliCtx.WithHeight(height), bz)
}
}