diff --git a/x/auth/module.go b/x/auth/module.go index bd4ebc027a82..bf1f212f0c5f 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -118,6 +118,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.accountKeeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the auth module. It returns diff --git a/x/bank/module.go b/x/bank/module.go index 6719d364ce62..ee6659e3411b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -87,6 +87,8 @@ type AppModule struct { accountKeeper types.AccountKeeper } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(server grpc.Server) { types.RegisterQueryServer(server, am.keeper) } diff --git a/x/capability/module.go b/x/capability/module.go index 841265336fa2..f2a36ac5476b 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -104,6 +104,8 @@ func (AppModule) QuerierRoute() string { return "" } // NewQuerierHandler returns the capability module's Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { return nil } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // RegisterInvariants registers the capability module's invariants. diff --git a/x/crisis/module.go b/x/crisis/module.go index 54b6d40eadc6..b01bcfc94b01 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -109,6 +109,8 @@ func (AppModule) QuerierRoute() string { return "" } // NewQuerierHandler returns no sdk.Querier. func (AppModule) NewQuerierHandler() sdk.Querier { return nil } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the crisis module. It returns diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index d0364aa39825..5733bd5abfe1 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + "context" "fmt" "strconv" "strings" @@ -11,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/distribution/client/common" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -49,19 +49,14 @@ func GetCmdQueryParams() *cobra.Command { if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams) - res, _, err := clientCtx.QueryWithData(route, nil) + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) if err != nil { return err } - var params types.Params - if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, ¶ms); err != nil { - return fmt.Errorf("failed to unmarshal params: %w", err) - } - - return clientCtx.PrintOutput(params) + return clientCtx.PrintOutput(res.GetParams()) }, } @@ -91,32 +86,22 @@ $ %s query distribution validator-outstanding-rewards cosmosvaloper1lwjmdnks33xw if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) - valAddr, err := sdk.ValAddressFromBech32(args[0]) - if err != nil { - return err - } - - params := types.NewQueryValidatorOutstandingRewardsParams(valAddr) - bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) + validatorAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { return err } - resp, _, err := clientCtx.QueryWithData( - fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorOutstandingRewards), - bz, + res, err := queryClient.ValidatorOutstandingRewards( + context.Background(), + &types.QueryValidatorOutstandingRewardsRequest{ValidatorAddress: validatorAddr}, ) if err != nil { return err } - var outstandingRewards types.ValidatorOutstandingRewards - if err := clientCtx.JSONMarshaler.UnmarshalJSON(resp, &outstandingRewards); err != nil { - return err - } - - return clientCtx.PrintOutput(outstandingRewards) + return clientCtx.PrintOutput(res.GetRewards()) }, } @@ -145,23 +130,22 @@ $ %s query distribution commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9l if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) validatorAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { return err } - res, err := common.QueryValidatorCommission(clientCtx, validatorAddr) + res, err := queryClient.ValidatorCommission( + context.Background(), + &types.QueryValidatorCommissionRequest{ValidatorAddress: validatorAddr}, + ) if err != nil { return err } - var valCom types.ValidatorAccumulatedCommission - if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, &valCom); err != nil { - return err - } - - return clientCtx.PrintOutput(valCom) + return clientCtx.PrintOutput(res.GetCommission()) }, } @@ -190,6 +174,7 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) validatorAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -206,27 +191,27 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq return fmt.Errorf("end-height %s not a valid uint, please input a valid end-height", args[2]) } - params := types.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight) - bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) - if err != nil { - return err - } + pageReq := client.ReadPageRequest(cmd.Flags()) - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_slashes", types.QuerierRoute), bz) + res, err := queryClient.ValidatorSlashes( + context.Background(), + &types.QueryValidatorSlashesRequest{ + ValidatorAddress: validatorAddr, + StartingHeight: startHeight, + EndingHeight: endHeight, + Req: pageReq, + }, + ) if err != nil { return err } - var slashes []types.ValidatorSlashEvent - if err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &slashes); err != nil { - return fmt.Errorf("failed to unmarshal response: %w", err) - } - - return clientCtx.PrintOutput(slashes) + return clientCtx.PrintOutput(res.GetSlashes()) }, } flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "validator slashes") return cmd } @@ -252,46 +237,40 @@ $ %s query distribution rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) + + delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } // query for rewards from a particular delegation if len(args) == 2 { - resp, _, err := common.QueryDelegationRewards(clientCtx, args[0], args[1]) + validatorAddr, err := sdk.ValAddressFromBech32(args[1]) if err != nil { return err } - var result sdk.DecCoins - if err = clientCtx.JSONMarshaler.UnmarshalJSON(resp, &result); err != nil { - return fmt.Errorf("failed to unmarshal response: %w", err) + res, err := queryClient.DelegationRewards( + context.Background(), + &types.QueryDelegationRewardsRequest{DelegatorAddress: delegatorAddr, ValidatorAddress: validatorAddr}, + ) + if err != nil { + return err } - return clientCtx.PrintOutput(result) - } - - delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - params := types.NewQueryDelegatorParams(delegatorAddr) - bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) - if err != nil { - return fmt.Errorf("failed to marshal params: %w", err) + return clientCtx.PrintOutput(res.GetRewards()) } - // query for delegator total rewards - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorTotalRewards) - res, _, err := clientCtx.QueryWithData(route, bz) + res, err := queryClient.DelegationTotalRewards( + context.Background(), + &types.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegatorAddr}, + ) if err != nil { return err } - var result types.QueryDelegatorTotalRewardsResponse - if err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &result); err != nil { - return fmt.Errorf("failed to unmarshal response: %w", err) - } - - return clientCtx.PrintOutput(result) + return clientCtx.PrintOutput(res) }, } @@ -299,7 +278,7 @@ $ %s query distribution rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co return cmd } -// GetCmdQueryCommunityPool returns the command for fetching community pool info +// GetCmdQueryCommunityPool returns the command for fetching community pool info. func GetCmdQueryCommunityPool() *cobra.Command { cmd := &cobra.Command{ Use: "community-pool", @@ -320,18 +299,14 @@ $ %s query distribution community-pool if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", types.QuerierRoute), nil) + res, err := queryClient.CommunityPool(context.Background(), &types.QueryCommunityPoolRequest{}) if err != nil { return err } - var result sdk.DecCoins - if err := clientCtx.JSONMarshaler.UnmarshalJSON(res, &result); err != nil { - return err - } - - return clientCtx.PrintOutput(result) + return clientCtx.PrintOutput(res.GetPool()) }, } diff --git a/x/distribution/module.go b/x/distribution/module.go index 6ed56e413d04..738bcfbf3861 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -134,6 +134,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(server grpc.Server) { types.RegisterQueryServer(server, am.keeper) } diff --git a/x/evidence/module.go b/x/evidence/module.go index 5bad8e4d9c30..493998262364 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -143,6 +143,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // RegisterInvariants registers the evidence module's invariants. diff --git a/x/gov/client/cli/parse_test.go b/x/gov/client/cli/parse_test.go index 8ac3e70e2fcf..37e41f57c56d 100644 --- a/x/gov/client/cli/parse_test.go +++ b/x/gov/client/cli/parse_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/testutil" ) @@ -23,7 +22,7 @@ func TestParseSubmitProposalFlags(t *testing.T) { badJSON, cleanup2 := testutil.WriteToNewTempFile(t, "bad json") t.Cleanup(cleanup2) - fs := NewCmdSubmitProposal(client.Context{}).Flags() + fs := NewCmdSubmitProposal().Flags() // nonexistent json fs.Set(FlagProposal, "fileDoesNotExist") diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index b3d911174800..47b7b91710d0 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + "context" "fmt" "strconv" "strings" @@ -9,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" @@ -17,7 +17,7 @@ import ( ) // GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetQueryCmd() *cobra.Command { // Group gov queries under a subcommand govQueryCmd := &cobra.Command{ Use: types.ModuleName, @@ -28,23 +28,23 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { } govQueryCmd.AddCommand( - GetCmdQueryProposal(queryRoute, cdc), - GetCmdQueryProposals(queryRoute, cdc), - GetCmdQueryVote(queryRoute, cdc), - GetCmdQueryVotes(queryRoute, cdc), - GetCmdQueryParam(queryRoute, cdc), - GetCmdQueryParams(queryRoute, cdc), - GetCmdQueryProposer(queryRoute, cdc), - GetCmdQueryDeposit(queryRoute, cdc), - GetCmdQueryDeposits(queryRoute, cdc), - GetCmdQueryTally(queryRoute, cdc), + GetCmdQueryProposal(), + GetCmdQueryProposals(), + GetCmdQueryVote(), + GetCmdQueryVotes(), + GetCmdQueryParam(), + GetCmdQueryParams(), + GetCmdQueryProposer(), + GetCmdQueryDeposit(), + GetCmdQueryDeposits(), + GetCmdQueryTally(), ) return govQueryCmd } // GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryProposal() *cobra.Command { cmd := &cobra.Command{ Use: "proposal [proposal-id]", Args: cobra.ExactArgs(1), @@ -60,7 +60,12 @@ $ %s query gov proposal 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -69,14 +74,15 @@ $ %s query gov proposal 1 } // Query the proposal - res, err := gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + res, err := queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { return err } - var proposal types.Proposal - cdc.MustUnmarshalJSON(res, &proposal) - return clientCtx.PrintOutput(proposal) // nolint:errcheck + return clientCtx.PrintOutput(res.GetProposal()) }, } @@ -85,8 +91,9 @@ $ %s query gov proposal 1 return cmd } -// GetCmdQueryProposals implements a query proposals command. -func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdQueryProposals implements a query proposals command. Command to Get a +// Proposal Information. +func GetCmdQueryProposals() *cobra.Command { cmd := &cobra.Command{ Use: "proposals", Short: "Query proposals with optional filters", @@ -106,78 +113,64 @@ $ %s query gov proposals --page=2 --limit=100 bechDepositorAddr, _ := cmd.Flags().GetString(flagDepositor) bechVoterAddr, _ := cmd.Flags().GetString(flagVoter) strProposalStatus, _ := cmd.Flags().GetString(flagStatus) - page, _ := cmd.Flags().GetInt(flags.FlagPage) - limit, _ := cmd.Flags().GetInt(flags.FlagLimit) - - var depositorAddr sdk.AccAddress - var voterAddr sdk.AccAddress - var proposalStatus types.ProposalStatus - - params := types.NewQueryProposalsParams(page, limit, proposalStatus, voterAddr, depositorAddr) - - if len(bechDepositorAddr) != 0 { - depositorAddr, err := sdk.AccAddressFromBech32(bechDepositorAddr) - if err != nil { - return err - } - params.Depositor = depositorAddr - } - if len(bechVoterAddr) != 0 { - voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr) - if err != nil { - return err - } - params.Voter = voterAddr + depositorAddr, err := sdk.AccAddressFromBech32(bechDepositorAddr) + if err != nil { + return err } - if len(strProposalStatus) != 0 { - proposalStatus, err := types.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus)) - if err != nil { - return err - } - params.ProposalStatus = proposalStatus + voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr) + if err != nil { + return err } - bz, err := cdc.MarshalJSON(params) + proposalStatus, err := types.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus)) if err != nil { return err } - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) - - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err = client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) - var matchingProposals types.Proposals - err = cdc.UnmarshalJSON(res, &matchingProposals) + pageReq := client.ReadPageRequest(cmd.Flags()) + + res, err := queryClient.Proposals( + context.Background(), + &types.QueryProposalsRequest{ + ProposalStatus: proposalStatus, + Voter: voterAddr, + Depositor: depositorAddr, + Req: pageReq, + }, + ) if err != nil { return err } - if len(matchingProposals) == 0 { + if len(res.GetProposals()) == 0 { return fmt.Errorf("no matching proposals found") } - return clientCtx.PrintOutput(matchingProposals) // nolint:errcheck + return clientCtx.PrintOutput(res.GetProposals()) }, } - cmd.Flags().Int(flags.FlagPage, 1, "pagination page of proposals to to query for") - cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of proposals to query for") cmd.Flags().String(flagDepositor, "", "(optional) filter by proposals deposited on by depositor") cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted") cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status, status: deposit_period/voting_period/passed/rejected") + flags.AddPaginationFlagsToCmd(cmd, "proposals") flags.AddQueryFlagsToCmd(cmd) return cmd } -// Command to Get a Proposal Information -// GetCmdQueryVote implements the query proposal vote command. -func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdQueryVote implements the query proposal vote command. Command to Get a +// Proposal Information. +func GetCmdQueryVote() *cobra.Command { cmd := &cobra.Command{ Use: "vote [proposal-id] [voter-addr]", Args: cobra.ExactArgs(2), @@ -192,7 +185,12 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -201,7 +199,10 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } // check to see if the proposal is in the store - _, err = gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + _, err = queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } @@ -211,36 +212,29 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return err } - params := types.NewQueryVoteParams(proposalID, voterAddr) - bz, err := cdc.MarshalJSON(params) - if err != nil { - return err - } - - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz) + res, err := queryClient.Vote( + context.Background(), + &types.QueryVoteRequest{ProposalId: proposalID, Voter: voterAddr}, + ) if err != nil { return err } - var vote types.Vote - - // XXX: Allow the decoding to potentially fail as the vote may have been - // pruned from state. If so, decoding will fail and so we need to check the - // Empty() case. Consider updating Vote JSON decoding to not fail when empty. - _ = cdc.UnmarshalJSON(res, &vote) - + vote := res.GetVote() if vote.Empty() { - res, err = gcutils.QueryVoteByTxQuery(clientCtx, params) + params := types.NewQueryVoteParams(proposalID, voterAddr) + resByTxQuery, err := gcutils.QueryVoteByTxQuery(clientCtx, params) + if err != nil { return err } - if err := cdc.UnmarshalJSON(res, &vote); err != nil { + if err := clientCtx.JSONMarshaler.UnmarshalJSON(resByTxQuery, &vote); err != nil { return err } } - return clientCtx.PrintOutput(vote) + return clientCtx.PrintOutput(res.GetVote()) }, } @@ -250,7 +244,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } // GetCmdQueryVotes implements the command to query for proposal votes. -func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryVotes() *cobra.Command { cmd := &cobra.Command{ Use: "votes [proposal-id]", Args: cobra.ExactArgs(1), @@ -266,7 +260,12 @@ $ %[1]s query gov votes 1 --page=2 --limit=100 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -274,51 +273,59 @@ $ %[1]s query gov votes 1 --page=2 --limit=100 return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) } - page, _ := cmd.Flags().GetInt(flags.FlagPage) - limit, _ := cmd.Flags().GetInt(flags.FlagLimit) - - params := types.NewQueryProposalVotesParams(proposalID, page, limit) - bz, err := cdc.MarshalJSON(params) - if err != nil { - return err - } - // check to see if the proposal is in the store - res, err := gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + proposalRes, err := queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } - var proposal types.Proposal - cdc.MustUnmarshalJSON(res, &proposal) - - propStatus := proposal.Status + propStatus := proposalRes.GetProposal().Status if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { - res, err = gcutils.QueryVotesByTxQuery(clientCtx, params) - } else { - res, _, err = clientCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz) + page, _ := cmd.Flags().GetInt(flags.FlagPage) + limit, _ := cmd.Flags().GetInt(flags.FlagLimit) + + params := types.NewQueryProposalVotesParams(proposalID, page, limit) + resByTxQuery, err := gcutils.QueryVotesByTxQuery(clientCtx, params) + if err != nil { + return err + } + + var votes types.Votes + clientCtx.JSONMarshaler.MustUnmarshalJSON(resByTxQuery, &votes) + return clientCtx.PrintOutput(votes) + } + pageReq := client.ReadPageRequest(cmd.Flags()) + + res, err := queryClient.Votes( + context.Background(), + &types.QueryVotesRequest{ProposalId: proposalID, Req: pageReq}, + ) if err != nil { return err } - var votes types.Votes - cdc.MustUnmarshalJSON(res, &votes) - return clientCtx.PrintOutput(votes) + return clientCtx.PrintOutput(res.GetVotes()) + }, } - cmd.Flags().Int(flags.FlagPage, 1, "pagination page of votes to to query for") - cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of votes to query for") + // Deprecated, remove line when removing FlagPage altogether. + cmd.Flags().Int(flags.FlagPage, 1, "pagination page of proposals to to query for") + + flags.AddPaginationFlagsToCmd(cmd, "votes") flags.AddQueryFlagsToCmd(cmd) return cmd } -// Command to Get a specific Deposit Information -// GetCmdQueryDeposit implements the query proposal deposit command. -func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdQueryDeposit implements the query proposal deposit command. Command to +// get a specific Deposit Information +func GetCmdQueryDeposit() *cobra.Command { cmd := &cobra.Command{ Use: "deposit [proposal-id] [depositer-addr]", Args: cobra.ExactArgs(2), @@ -333,7 +340,12 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -342,7 +354,10 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } // check to see if the proposal is in the store - _, err = gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + _, err = queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } @@ -352,26 +367,22 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return err } - params := types.NewQueryDepositParams(proposalID, depositorAddr) - bz, err := cdc.MarshalJSON(params) - if err != nil { - return err - } - - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz) + res, err := queryClient.Deposit( + context.Background(), + &types.QueryDepositRequest{ProposalId: proposalID, Depositor: depositorAddr}, + ) if err != nil { return err } - var deposit types.Deposit - cdc.MustUnmarshalJSON(res, &deposit) - + deposit := res.GetDeposit() if deposit.Empty() { - res, err = gcutils.QueryDepositByTxQuery(clientCtx, params) + params := types.NewQueryDepositParams(proposalID, depositorAddr) + resByTxQuery, err := gcutils.QueryDepositByTxQuery(clientCtx, params) if err != nil { return err } - cdc.MustUnmarshalJSON(res, &deposit) + clientCtx.JSONMarshaler.MustUnmarshalJSON(resByTxQuery, &deposit) } return clientCtx.PrintOutput(deposit) @@ -384,7 +395,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } // GetCmdQueryDeposits implements the command to query for proposal deposits. -func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryDeposits() *cobra.Command { cmd := &cobra.Command{ Use: "deposits [proposal-id]", Args: cobra.ExactArgs(1), @@ -400,7 +411,12 @@ $ %s query gov deposits 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -408,45 +424,50 @@ $ %s query gov deposits 1 return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) } - params := types.NewQueryProposalParams(proposalID) - bz, err := cdc.MarshalJSON(params) - if err != nil { - return err - } - // check to see if the proposal is in the store - res, err := gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + proposalRes, err := queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { - return fmt.Errorf("failed to fetch proposal with id %d: %s", proposalID, err) + return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } - var proposal types.Proposal - cdc.MustUnmarshalJSON(res, &proposal) - - propStatus := proposal.Status + propStatus := proposalRes.GetProposal().Status if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { - res, err = gcutils.QueryDepositsByTxQuery(clientCtx, params) - } else { - res, _, err = clientCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz) + params := types.NewQueryProposalParams(proposalID) + resByTxQuery, err := gcutils.QueryDepositsByTxQuery(clientCtx, params) + if err != nil { + return err + } + + var dep types.Deposits + clientCtx.JSONMarshaler.MustUnmarshalJSON(resByTxQuery, &dep) + return clientCtx.PrintOutput(dep) } + pageReq := client.ReadPageRequest(cmd.Flags()) + + res, err := queryClient.Deposits( + context.Background(), + &types.QueryDepositsRequest{ProposalId: proposalID, Req: pageReq}, + ) if err != nil { return err } - var dep types.Deposits - cdc.MustUnmarshalJSON(res, &dep) - return clientCtx.PrintOutput(dep) + return clientCtx.PrintOutput(res.GetDeposits()) }, } + flags.AddPaginationFlagsToCmd(cmd, "deposits") flags.AddQueryFlagsToCmd(cmd) return cmd } // GetCmdQueryTally implements the command to query for proposal tally result. -func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryTally() *cobra.Command { cmd := &cobra.Command{ Use: "tally [proposal-id]", Args: cobra.ExactArgs(1), @@ -462,7 +483,12 @@ $ %s query gov tally 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -471,27 +497,24 @@ $ %s query gov tally 1 } // check to see if the proposal is in the store - _, err = gcutils.QueryProposalByID(proposalID, clientCtx, queryRoute) + _, err = queryClient.Proposal( + context.Background(), + &types.QueryProposalRequest{ProposalId: proposalID}, + ) if err != nil { return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) } - // Construct query - params := types.NewQueryProposalParams(proposalID) - bz, err := cdc.MarshalJSON(params) - if err != nil { - return err - } - // Query store - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/tally", queryRoute), bz) + res, err := queryClient.TallyResult( + context.Background(), + &types.QueryTallyResultRequest{ProposalId: proposalID}, + ) if err != nil { return err } - var tally types.TallyResult - cdc.MustUnmarshalJSON(res, &tally) - return clientCtx.PrintOutput(tally) + return clientCtx.PrintOutput(res.GetTally()) }, } @@ -500,8 +523,8 @@ $ %s query gov tally 1 return cmd } -// GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdQueryParams implements the query params command. +func GetCmdQueryParams() *cobra.Command { cmd := &cobra.Command{ Use: "params", Short: "Query the parameters of the governance process", @@ -516,28 +539,43 @@ $ %s query gov params ), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) - tp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/tallying", queryRoute), nil) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) if err != nil { return err } - dp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/deposit", queryRoute), nil) + queryClient := types.NewQueryClient(clientCtx) + + // Query store for all 3 params + votingRes, err := queryClient.Params( + context.Background(), + &types.QueryParamsRequest{ParamsType: "voting"}, + ) if err != nil { return err } - vp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/voting", queryRoute), nil) + + tallyRes, err := queryClient.Params( + context.Background(), + &types.QueryParamsRequest{ParamsType: "tallying"}, + ) if err != nil { return err } - var tallyParams types.TallyParams - cdc.MustUnmarshalJSON(tp, &tallyParams) - var depositParams types.DepositParams - cdc.MustUnmarshalJSON(dp, &depositParams) - var votingParams types.VotingParams - cdc.MustUnmarshalJSON(vp, &votingParams) + depositRes, err := queryClient.Params( + context.Background(), + &types.QueryParamsRequest{ParamsType: "deposit"}, + ) + if err != nil { + return err + } - return clientCtx.PrintOutput(types.NewParams(votingParams, tallyParams, depositParams)) + return clientCtx.PrintOutput(types.NewParams( + votingRes.GetVotingParams(), + tallyRes.GetTallyParams(), + depositRes.GetDepositParams(), + )) }, } @@ -546,8 +584,8 @@ $ %s query gov params return cmd } -// GetCmdQueryProposal implements the query proposal command. -func GetCmdQueryParam(queryRoute string, cdc *codec.Codec) *cobra.Command { +// GetCmdQueryParam implements the query param command. +func GetCmdQueryParam() *cobra.Command { cmd := &cobra.Command{ Use: "param [param-type]", Args: cobra.ExactArgs(1), @@ -564,27 +602,30 @@ $ %s query gov param deposit ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) // Query store - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, args[0]), nil) + res, err := queryClient.Params( + context.Background(), + &types.QueryParamsRequest{ParamsType: args[0]}, + ) if err != nil { return err } + var out fmt.Stringer switch args[0] { case "voting": - var param types.VotingParams - cdc.MustUnmarshalJSON(res, ¶m) - out = param + out = res.GetVotingParams() case "tallying": - var param types.TallyParams - cdc.MustUnmarshalJSON(res, ¶m) - out = param + out = res.GetTallyParams() case "deposit": - var param types.DepositParams - cdc.MustUnmarshalJSON(res, ¶m) - out = param + out = res.GetDepositParams() default: return fmt.Errorf("argument must be one of (voting|tallying|deposit), was %s", args[0]) } @@ -599,7 +640,7 @@ $ %s query gov param deposit } // GetCmdQueryProposer implements the query proposer command. -func GetCmdQueryProposer(queryRoute string, cdc *codec.Codec) *cobra.Command { +func GetCmdQueryProposer() *cobra.Command { cmd := &cobra.Command{ Use: "proposer [proposal-id]", Args: cobra.ExactArgs(1), @@ -614,7 +655,11 @@ $ %s query gov proposer 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } // validate that the proposalID is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index a214fbaed15c..d7145ec6b4ac 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -50,7 +50,7 @@ var ProposalFlags = []string{ // it contains a slice of "proposal" child commands. These commands are respective // to proposal type handlers that are implemented in other modules but are mounted // under the governance CLI (eg. parameter change proposals). -func NewTxCmd(ctx client.Context, propCmds []*cobra.Command) *cobra.Command { +func NewTxCmd(propCmds []*cobra.Command) *cobra.Command { govTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Governance transactions subcommands", @@ -59,14 +59,14 @@ func NewTxCmd(ctx client.Context, propCmds []*cobra.Command) *cobra.Command { RunE: client.ValidateCmd, } - cmdSubmitProp := NewCmdSubmitProposal(ctx) + cmdSubmitProp := NewCmdSubmitProposal() for _, propCmd := range propCmds { cmdSubmitProp.AddCommand(propCmd) } govTxCmd.AddCommand( - NewCmdDeposit(ctx), - NewCmdVote(ctx), + NewCmdDeposit(), + NewCmdVote(), cmdSubmitProp, ) @@ -74,7 +74,7 @@ func NewTxCmd(ctx client.Context, propCmds []*cobra.Command) *cobra.Command { } // NewCmdSubmitProposal implements submitting a proposal transaction command. -func NewCmdSubmitProposal(clientCtx client.Context) *cobra.Command { +func NewCmdSubmitProposal() *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal", Short: "Submit a proposal along with an initial deposit", @@ -102,7 +102,11 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := clientCtx.InitWithInput(cmd.InOrStdin()) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } proposal, err := parseSubmitProposalFlags(cmd.Flags()) if err != nil { @@ -140,7 +144,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr } // NewCmdDeposit implements depositing tokens for an active proposal. -func NewCmdDeposit(clientCtx client.Context) *cobra.Command { +func NewCmdDeposit() *cobra.Command { cmd := &cobra.Command{ Use: "deposit [proposal-id] [deposit]", Args: cobra.ExactArgs(2), @@ -156,7 +160,11 @@ $ %s tx gov deposit 1 10stake --from mykey ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := clientCtx.InitWithInput(cmd.InOrStdin()) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -189,7 +197,7 @@ $ %s tx gov deposit 1 10stake --from mykey } // NewCmdVote implements creating a new vote command. -func NewCmdVote(clientCtx client.Context) *cobra.Command { +func NewCmdVote() *cobra.Command { cmd := &cobra.Command{ Use: "vote [proposal-id] [option]", Args: cobra.ExactArgs(2), @@ -206,7 +214,11 @@ $ %s tx gov vote 1 yes --from mykey ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := clientCtx.InitWithInput(cmd.InOrStdin()) + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } // Get voting address from := clientCtx.GetFromAddress() diff --git a/x/gov/module.go b/x/gov/module.go index 27593ee6072a..40e8ebf45cdc 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -85,18 +85,18 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro } // GetTxCmd returns the root tx command for the gov module. -func (a AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command { +func (a AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command { proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) for _, proposalHandler := range a.proposalHandlers { proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler()) } - return cli.NewTxCmd(clientCtx, proposalCLIHandlers) + return cli.NewTxCmd(proposalCLIHandlers) } // GetQueryCmd returns the root query command for the gov module. -func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command { - return cli.GetQueryCmd(types.StoreKey, clientCtx.Codec) +func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command { + return cli.GetQueryCmd() } // RegisterInterfaceTypes implements InterfaceModule.RegisterInterfaceTypes @@ -150,6 +150,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(server grpc.Server) { types.RegisterQueryServer(server, am.keeper) } diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 8542c4b9e994..6f53de7bec56 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -118,6 +118,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return nil } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the ibc transfer module. It returns diff --git a/x/mint/module.go b/x/mint/module.go index 39c549280eb8..013ca97124da 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -113,6 +113,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the mint module. It returns diff --git a/x/params/client/cli/cli_test.go b/x/params/client/cli/cli_test.go index ff487548c599..8f99689337e9 100644 --- a/x/params/client/cli/cli_test.go +++ b/x/params/client/cli/cli_test.go @@ -53,7 +53,7 @@ func (s *IntegrationTestSuite) TestNewQuerySubspaceParamsCmd() { []string{ "staking", "MaxValidators", }, - `{"Subspace":"staking","Key":"MaxValidators","Value":"100"}`, + `{"subspace":"staking","key":"MaxValidators","value":"100"}`, }, { "text output", @@ -61,9 +61,9 @@ func (s *IntegrationTestSuite) TestNewQuerySubspaceParamsCmd() { "staking", "MaxValidators", fmt.Sprintf("--%s=text", tmcli.OutputFlag), }, - `Key: MaxValidators -Subspace: staking -Value: "100"`, + `key: MaxValidators +subspace: staking +value: "100"`, }, } diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index 687ff74bf4c8..b9c4b24d1778 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -1,13 +1,14 @@ package cli import ( - "fmt" + "context" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" ) // NewQueryCmd returns a root CLI command handler for all x/params query commands. @@ -38,26 +39,15 @@ func NewQuerySubspaceParamsCmd() *cobra.Command { if err != nil { return err } + queryClient := proposal.NewQueryClient(clientCtx) - params := types.NewQuerySubspaceParams(args[0], args[1]) - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams) - - bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) - if err != nil { - return fmt.Errorf("failed to marshal params: %w", err) - } - - bz, _, err = clientCtx.QueryWithData(route, bz) + params := proposal.NewQueryParametersRequest(args[0], args[1]) + res, err := queryClient.Parameters(context.Background(), params) if err != nil { return err } - var resp types.SubspaceParamsResponse - if err := clientCtx.JSONMarshaler.UnmarshalJSON(bz, &resp); err != nil { - return err - } - - return clientCtx.PrintOutput(resp) + return clientCtx.PrintOutput(res.GetParams()) }, } diff --git a/x/params/module.go b/x/params/module.go index 9e4256a2b7aa..148113e60ecd 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -102,7 +102,11 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } -func (am AppModule) RegisterQueryService(grpc.Server) {} +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterQueryService(server grpc.Server) { + proposal.RegisterQueryServer(server, am.keeper) +} // ProposalContents returns all the params content functions used to // simulate governance proposals. diff --git a/x/staking/module.go b/x/staking/module.go index 77a66a8ca907..db9476f2606f 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -121,6 +121,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. func (am AppModule) RegisterQueryService(grpc.Server) {} // InitGenesis performs genesis initialization for the staking module. It returns diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index de45e805f77a..a555cfc90089 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) -// GetQueryCmd returns the parent command for all x/upgrade CLi query commands +// GetQueryCmd returns the parent command for all x/upgrade CLi query commands. func GetQueryCmd() *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, @@ -26,7 +26,7 @@ func GetQueryCmd() *cobra.Command { return cmd } -// GetCurrentPlanCmd returns the query upgrade plan command +// GetCurrentPlanCmd returns the query upgrade plan command. func GetCurrentPlanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "plan", @@ -35,10 +35,14 @@ func GetCurrentPlanCmd() *cobra.Command { Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } queryClient := types.NewQueryClient(clientCtx) - params := types.NewQueryCurrentPlanRequest() - res, err := queryClient.CurrentPlan(context.Background(), params) + params := types.QueryCurrentPlanRequest{} + res, err := queryClient.CurrentPlan(context.Background(), ¶ms) if err != nil { return err } @@ -47,10 +51,7 @@ func GetCurrentPlanCmd() *cobra.Command { return fmt.Errorf("no upgrade scheduled") } - if err != nil { - return err - } - return clientCtx.PrintOutput(res.Plan) + return clientCtx.PrintOutput(res.GetPlan()) }, } @@ -60,7 +61,7 @@ func GetCurrentPlanCmd() *cobra.Command { } // GetAppliedPlanCmd returns information about the block at which a completed -// upgrade was applied +// upgrade was applied. func GetAppliedPlanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "applied [upgrade-name]", @@ -70,11 +71,14 @@ func GetAppliedPlanCmd() *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } queryClient := types.NewQueryClient(clientCtx) - name := args[0] - params := types.NewQueryAppliedPlanRequest(name) - res, err := queryClient.AppliedPlan(context.Background(), params) + params := types.QueryAppliedPlanRequest{Name: args[0]} + res, err := queryClient.AppliedPlan(context.Background(), ¶ms) if err != nil { return err } diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index 02f0303a4c50..709b78687c68 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -45,7 +45,7 @@ func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *htt return func(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] - params := types.NewQueryAppliedPlanRequest(name) + params := types.QueryAppliedPlanRequest{Name: name} bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index c0f0601b4758..1ffb0038f6cd 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -46,7 +46,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() { { "without current upgrade plan", func() { - req = types.NewQueryCurrentPlanRequest() + req = &types.QueryCurrentPlanRequest{} expResponse = types.QueryCurrentPlanResponse{} }, true, @@ -57,7 +57,7 @@ func (suite *UpgradeTestSuite) TestQueryCurrentPlan() { plan := types.Plan{Name: "test-plan", Height: 5} suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan) - req = types.NewQueryCurrentPlanRequest() + req = &types.QueryCurrentPlanRequest{} expResponse = types.QueryCurrentPlanResponse{Plan: &plan} }, true, @@ -97,7 +97,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { { "with non-existent upgrade plan", func() { - req = types.NewQueryAppliedPlanRequest("foo") + req = &types.QueryAppliedPlanRequest{Name: "foo"} }, true, }, @@ -114,7 +114,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan) {}) suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan) - req = types.NewQueryAppliedPlanRequest(planName) + req = &types.QueryAppliedPlanRequest{Name: planName} }, true, }, diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 472300445b99..7caa7b55b658 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -94,7 +94,11 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { return keeper.NewQuerier(am.keeper) } -func (am AppModule) RegisterQueryService(grpc.Server) {} +// RegisterQueryService registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterQueryService(server grpc.Server) { + types.RegisterQueryServer(server, am.keeper) +} // InitGenesis is ignored, no sense in serializing future upgrades func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/upgrade/types/querier.go b/x/upgrade/types/querier.go index b6b6457ca833..d636c6aa9676 100644 --- a/x/upgrade/types/querier.go +++ b/x/upgrade/types/querier.go @@ -5,13 +5,3 @@ const ( QueryCurrent = "current" QueryApplied = "applied" ) - -// NewQueryCurrentPlanRequest creates a new instance of QueryCurrentPlanRequest. -func NewQueryCurrentPlanRequest() *QueryCurrentPlanRequest { - return &QueryCurrentPlanRequest{} -} - -// NewQueryAppliedPlanRequest creates a new instance of QueryAppliedPlanRequest. -func NewQueryAppliedPlanRequest(name string) *QueryAppliedPlanRequest { - return &QueryAppliedPlanRequest{Name: name} -}