Skip to content

Commit

Permalink
feat(tally): query endpoint for module parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Dec 16, 2024
1 parent b6a0753 commit 9bc597c
Show file tree
Hide file tree
Showing 6 changed files with 624 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ import (
"github.com/sedaprotocol/seda-chain/app/keepers"
appparams "github.com/sedaprotocol/seda-chain/app/params"
"github.com/sedaprotocol/seda-chain/app/utils"

// Used in cosmos-sdk when registering the route for swagger docs.
_ "github.com/sedaprotocol/seda-chain/client/docs/statik"
"github.com/sedaprotocol/seda-chain/cmd/sedad/gentx"
Expand Down
51 changes: 51 additions & 0 deletions x/tally/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/sedaprotocol/seda-chain/x/tally/types"
)

// GetQueryCmd returns the CLI query commands for this module.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
GetCmdQueryParams(),
)
return cmd
}

func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query tally module parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
24 changes: 24 additions & 0 deletions x/tally/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/tally/types"
)

var _ types.QueryServer = Querier{}

type Querier struct {
Keeper
}

func (q Querier) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params, err := q.Keeper.GetParams(ctx)
if err != nil {
return nil, err
}
return &types.QueryParamsResponse{Params: params}, nil
}
4 changes: 4 additions & 0 deletions x/tally/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
return k.params.Set(ctx, params)
}

func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) {
return k.params.Get(ctx)
}

func (k Keeper) GetMaxTallyGasLimit(ctx sdk.Context) (uint64, error) {
params, err := k.params.Get(ctx)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions x/tally/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/sedaprotocol/seda-chain/x/tally/client/cli"
"github.com/sedaprotocol/seda-chain/x/tally/keeper"
"github.com/sedaprotocol/seda-chain/x/tally/types"
)
Expand Down Expand Up @@ -77,7 +78,12 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / linux-arm64

undefined: types.RegisterQueryHandlerClient

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / linux-amd64

undefined: types.RegisterQueryHandlerClient

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / darwin-arm64

undefined: types.RegisterQueryHandlerClient

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / darwin-amd64

undefined: types.RegisterQueryHandlerClient

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.RegisterQueryHandlerClient (typecheck)

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.RegisterQueryHandlerClient) (typecheck)

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: types.RegisterQueryHandlerClient

Check failure on line 82 in x/tally/module.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: types.RegisterQueryHandlerClient
if err != nil {
panic(err)
}
}

// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
Expand All @@ -86,7 +92,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {

// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
Expand All @@ -109,6 +115,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.Querier{Keeper: am.keeper})
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand Down
Loading

0 comments on commit 9bc597c

Please sign in to comment.