Skip to content

Commit

Permalink
feat: Added query for provider parameters (#1605)
Browse files Browse the repository at this point in the history
Added query for provider parameters
  • Loading branch information
bermuell authored Jan 31, 2024
1 parent 196c327 commit f5afcb7
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added query for current values of all provider parameters
([\#1605](https://github.com/cosmos/interchain-security/pull/1605))
16 changes: 15 additions & 1 deletion proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ service Query {
returns (QueryAllPairsValConAddrByConsumerChainIDResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/consumer_chain_id";
}
}

// QueryParams returns all current values of provider parameters
rpc QueryParams(QueryParamsRequest)
returns (QueryParamsResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/params";
}
}

message QueryConsumerGenesisRequest { string chain_id = 1; }
Expand Down Expand Up @@ -198,3 +205,10 @@ message PairValConAddrProviderAndConsumer {
string consumer_address = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];
tendermint.crypto.PublicKey consumer_key = 3;
}

message QueryParamsRequest {}

message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

37 changes: 36 additions & 1 deletion x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewQueryCmd() *cobra.Command {
cmd.AddCommand(CmdRegisteredConsumerRewardDenoms())
cmd.AddCommand(CmdProposedConsumerChains())
cmd.AddCommand(CmdAllPairsValConAddrByConsumerChainID())

cmd.AddCommand(CmdProviderParameters())
return cmd
}

Expand Down Expand Up @@ -375,3 +375,38 @@ func CmdAllPairsValConAddrByConsumerChainID() *cobra.Command {

return cmd
}

// Command to query provider parameters
func CmdProviderParameters() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query provider parameters information",
Long: strings.TrimSpace(
fmt.Sprintf(`Query parameter values of provider.
Example:
$ %s query provider params
`, version.AppName),
),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

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

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd

}
8 changes: 8 additions & 0 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,11 @@ func (k Keeper) QueryAllPairsValConAddrByConsumerChainID(goCtx context.Context,
PairValConAddr: pairValConAddrs,
}, nil
}

// QueryParams returns all parameters and current values of provider
func (k Keeper) QueryParams(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := k.GetParams(ctx)

return &types.QueryParamsResponse{Params: params}, nil
}
Loading

0 comments on commit f5afcb7

Please sign in to comment.