Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rest query the block config #3248

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/exchaind/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
govrest "github.com/okex/exchain/x/gov/client/rest"
orderrest "github.com/okex/exchain/x/order/client/rest"
paramsclient "github.com/okex/exchain/x/params/client"
paramsrest "github.com/okex/exchain/x/params/client/rest"
slashingrest "github.com/okex/exchain/x/slashing/client/rest"
stakingrest "github.com/okex/exchain/x/staking/client/rest"
"github.com/okex/exchain/x/token"
Expand Down Expand Up @@ -102,6 +103,7 @@ func registerRoutesV1(rs *lcd.RestServer, pathPrefix string) {
)
mintrest.RegisterRoutes(rs.CliCtx, v1Router)
ibctransferrest.RegisterOriginRPCRoutersForGRPC(rs.CliCtx, v1Router)
paramsrest.RegisterRoutes(rs.CliCtx, v1Router)
}

func registerRoutesV2(rs *lcd.RestServer, pathPrefix string) {
Expand Down
15 changes: 12 additions & 3 deletions x/params/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"github.com/okex/exchain/libs/cosmos-sdk/client/flags"
"strconv"
"strings"

"github.com/okex/exchain/x/params/types"
Expand Down Expand Up @@ -90,9 +91,17 @@ func GetCmdQueryBlockConfig(queryRoute string, cdc *codec.Codec) *cobra.Command

$ exchaincli query params blockconfig
`),
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
Args: cobra.MinimumNArgs(0),
RunE: func(_ *cobra.Command, args []string) error {
height := int64(0)
if len(args) > 0 {
var err error
height, err = strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
}
cliCtx := context.NewCLIContext().WithCodec(cdc).WithHeight(height)

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryBlockConfig)
bz, _, err := cliCtx.QueryWithData(route, nil)
Expand Down
36 changes: 36 additions & 0 deletions x/params/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package rest

import (
"fmt"
"github.com/gorilla/mux"
"github.com/okex/exchain/libs/cosmos-sdk/client/context"
"github.com/okex/exchain/libs/cosmos-sdk/types/rest"
"github.com/okex/exchain/x/common"
"github.com/okex/exchain/x/params"
"github.com/okex/exchain/x/params/types"
"net/http"
)

// RegisterRoutes, a central function to define routes
// which is called by the rest module in main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/params/blockconfig"), QueryBlockConfigFn(cliCtx)).Methods("GET")
}

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

route := fmt.Sprintf("custom/%s/%s", params.RouterKey, types.QueryBlockConfig)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
sdkErr := common.ParseSDKError(err.Error())
common.HandleErrorMsg(w, cliCtx, sdkErr.Code, err.Error())
return
}
rest.PostProcessResponseBare(w, cliCtx, bz)
}
}