[ENG-722]: Query x/builder module from CLI (#58)

This commit is contained in:
David Terpay 2023-04-13 13:03:07 -04:00 committed by GitHub
parent 06812560fc
commit 01d4f7ca71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 2 deletions

View File

@ -0,0 +1,53 @@
package cli
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/skip-mev/pob/x/builder/types"
"github.com/spf13/cobra"
)
// GetQueryCmd returns the cli query commands for the builder module.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
CmdQueryParams(),
)
return cmd
}
// CmdQueryParams implements a command that will return the current parameters of the builder module.
func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current parameters of the builder module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
request := &types.QueryParamsRequest{}
response, err := queryClient.Params(context.Background(), request)
if err != nil {
return err
}
return clientCtx.PrintProto(&response.Params)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/skip-mev/pob/x/builder/client/cli"
"github.com/skip-mev/pob/x/builder/keeper"
"github.com/skip-mev/pob/x/builder/types"
"github.com/spf13/cobra"
@ -71,8 +72,10 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
// GetTxCmd returns the root tx command for the builder module.
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
// GetQueryCmd returns no root query command for the builder module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }
// GetQueryCmd returns the root query command for the builder module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
type AppModule struct {
AppModuleBasic