/
query.go
40 lines (33 loc) · 1.22 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"
"net/http"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/coinexchain/cet-sdk/modules/bankx/internal/keeper"
"github.com/coinexchain/cet-sdk/modules/bankx/internal/types"
"github.com/coinexchain/cosmos-utils/client/restutil"
)
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.StoreKey, keeper.QueryParameters)
restutil.RestQuery(nil, cliCtx, w, r, route, nil, nil)
}
}
// query accountREST Handler
func QueryBalancesRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.StoreKey, keeper.QueryBalances)
vars := mux.Vars(r)
acc, err := sdk.AccAddressFromBech32(vars["address"])
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
params := keeper.NewQueryAddrBalances(acc)
restutil.RestQuery(cdc, cliCtx, w, r, route, ¶ms, nil)
}
}