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

feat: params query #433

Merged
merged 3 commits into from
Dec 9, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
go-version: 1.21.6
check-latest: true
- uses: golangci/golangci-lint-action@v3
- uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout 10m --tests=false --exclude-dirs="e2e"
Expand All @@ -33,7 +33,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Buf
uses: bufbuild/buf-setup-action@v1.26.1
uses: bufbuild/buf-setup-action@v1.47.2
- name: Lint Proto
run: make proto-lint
- name: clang-format Check
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ linters:
- misspell
- prealloc
- revive
- exportloopref
- copyloopvar
- staticcheck
- stylecheck
- typecheck
Expand Down
2 changes: 1 addition & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ breaking:
- FILE
lint:
use:
- DEFAULT
- STANDARD
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
Expand Down
14 changes: 14 additions & 0 deletions proto/sedachain/pubkey/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ option go_package = "github.com/sedaprotocol/seda-chain/x/pubkey/types";

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

// ValidatorKeys returns a given validator's registered keys.
rpc ValidatorKeys(QueryValidatorKeysRequest)
returns (QueryValidatorKeysResponse) {
Expand All @@ -25,6 +30,15 @@ service Query {
}
}

// 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 ];
}

// QueryValidatorKeysRequest is request type for the Query/ValidatorKeys
// RPC method.
message QueryValidatorKeysRequest {
Expand Down
25 changes: 25 additions & 0 deletions x/pubkey/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,37 @@ func GetQueryCmd() *cobra.Command {
}

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

func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current pubkey 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
}

// GetCmdValidatorKeys returns the command for querying a given
// validator's public keys.
func GetCmdValidatorKeys() *cobra.Command {
Expand Down
9 changes: 9 additions & 0 deletions x/pubkey/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ 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
}

func (q Querier) ValidatorKeys(ctx context.Context, req *types.QueryValidatorKeysRequest) (*types.QueryValidatorKeysResponse, error) {
result, err := q.GetValidatorKeys(ctx, req.ValidatorAddr)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions x/pubkey/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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) GetActivationBlockDelay(ctx sdk.Context) (int64, error) {
params, err := k.params.Get(ctx)
if err != nil {
Expand Down
Loading
Loading