diff --git a/cmd/okbchaind/rest.go b/cmd/okbchaind/rest.go index 7dd2b5fc1..681d5550a 100644 --- a/cmd/okbchaind/rest.go +++ b/cmd/okbchaind/rest.go @@ -25,6 +25,7 @@ import ( fsrest "github.com/okx/okbchain/x/feesplit/client/rest" govrest "github.com/okx/okbchain/x/gov/client/rest" paramsclient "github.com/okx/okbchain/x/params/client" + paramsrest "github.com/okx/okbchain/x/params/client/rest" stakingclient "github.com/okx/okbchain/x/staking/client" stakingrest "github.com/okx/okbchain/x/staking/client/rest" "github.com/okx/okbchain/x/token" @@ -80,7 +81,7 @@ func registerRoutesV1(rs *lcd.RestServer) { }, ) mintrest.RegisterRoutes(rs.CliCtx, v1Router) - + paramsrest.RegisterRoutes(rs.CliCtx, v1Router) } func registerRoutesV2(rs *lcd.RestServer) { diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index e695530ad..a64e76247 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "github.com/okx/okbchain/libs/cosmos-sdk/client/flags" + "strconv" "strings" "github.com/okx/okbchain/x/params/types" @@ -88,9 +89,17 @@ func GetCmdQueryBlockConfig(queryRoute string, cdc *codec.Codec) *cobra.Command Long: strings.TrimSpace(`Query parameters of blockconfig: $ 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) diff --git a/x/params/client/rest/rest.go b/x/params/client/rest/rest.go new file mode 100644 index 000000000..718779e5e --- /dev/null +++ b/x/params/client/rest/rest.go @@ -0,0 +1,36 @@ +package rest + +import ( + "fmt" + "github.com/gorilla/mux" + "github.com/okx/okbchain/libs/cosmos-sdk/client/context" + "github.com/okx/okbchain/libs/cosmos-sdk/types/rest" + "github.com/okx/okbchain/x/common" + "github.com/okx/okbchain/x/params" + "github.com/okx/okbchain/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) + } +}