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 17, 2024
1 parent 9ab86bb commit 035b083
Show file tree
Hide file tree
Showing 9 changed files with 803 additions and 4 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
25 changes: 25 additions & 0 deletions proto/sedachain/tally/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package sedachain.tally.v1;

import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "sedachain/tally/v1/tally.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/tally/types";

// Query defines the gRPC querier service.
service Query {
// Params returns the total set of tally parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/seda/tally/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
2 changes: 1 addition & 1 deletion x/batching/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func initFixture(tb testing.TB) *fixture {

keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, sdkstakingtypes.StoreKey, wasmstoragetypes.StoreKey,
wasmtypes.StoreKey, pubkeytypes.StoreKey, types.StoreKey,
wasmtypes.StoreKey, pubkeytypes.StoreKey, tallytypes.StoreKey, types.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, wasmstorage.AppModuleBasic{}).Codec

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))
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 035b083

Please sign in to comment.