Skip to content

Commit

Permalink
Merge PR: query Feesplit params by rest api (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylsGit authored Nov 14, 2022
1 parent 4e61647 commit 58aa732
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions x/feesplit/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,39 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/feesplit/contract/{contract}", contractHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/feesplit/deployer/{deployer}", deployerHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/feesplit/withdrawer/{withdrawer}", withdrawerHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/feesplit/parameters", queryParamsHandlerFn(cliCtx)).Methods("GET")
}

func RegisterRoutesV2(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/feesplit/contract/{contract}", contractHandlerFnV2(cliCtx)).Methods("GET")
r.HandleFunc("/feesplit/deployer/{deployer}", deployerHandlerFnV2(cliCtx)).Methods("GET")
r.HandleFunc("/feesplit/parameters", queryParamsHandlerFnV2(cliCtx)).Methods("GET")
}

// FeeSplitSharesProposalRESTHandler defines feesplit proposal handler
func FeeSplitSharesProposalRESTHandler(context.CLIContext) govRest.ProposalRESTHandler {
return govRest.ProposalRESTHandler{}
}

func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s",
types.RouterKey, types.QueryParameters), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}

func contractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
contract := mux.Vars(r)["contract"]
Expand Down Expand Up @@ -255,3 +276,34 @@ func deployerHandlerFnV2(cliCtx context.CLIContext) http.HandlerFunc {
rest.PostProcessResponse(w, cliCtx, resultJson)
}
}

func queryParamsHandlerFnV2(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s",
types.RouterKey, types.QueryParameters), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

var result types.QueryParamsResponse
if err := cliCtx.Codec.UnmarshalJSON(res, &result); err != nil {
comm.HandleErrorMsg(w, cliCtx, comm.CodeUnMarshalJSONFailed, err.Error())
return
}

resultJson, err := json.Marshal(comm.GetBaseResponse(result))
if err != nil {
comm.HandleErrorMsg(w, cliCtx, comm.CodeMarshalJSONFailed, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, resultJson)
}
}

0 comments on commit 58aa732

Please sign in to comment.