-
Notifications
You must be signed in to change notification settings - Fork 113
/
query.go
55 lines (46 loc) · 1.78 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
package rest
import (
"fmt"
"net/http"
"github.com/cosmos/cosmos-sdk/client"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/gorilla/mux"
"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/snapshot/keeper"
"github.com/axelarnetwork/axelar-core/x/snapshot/types"
)
// GetHandlerQueryProxy returns the proxy address associated to some operator address
func GetHandlerQueryProxy(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
address := mux.Vars(r)[utils.PathVarCosmosAddress]
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QProxy, address), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, sdkerrors.Wrap(err, types.ErrFProxyAddress).Error())
return
}
rest.PostProcessResponse(w, cliCtx, res)
}
}
// GetHandlerQueryOperator returns the operator address associated to some proxy address
func GetHandlerQueryOperator(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
address := mux.Vars(r)[utils.PathVarCosmosAddress]
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QOperator, address), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, sdkerrors.Wrap(err, types.ErrFOperatorAddress).Error())
return
}
rest.PostProcessResponse(w, cliCtx, string(res))
}
}