x/{gov,params,upgrade,distribution} CLI: In-Process test & use grpc query service (#6664)

* refactor CLI to use grpc query service

* In process CLI for gov

* ReadQueryCommandFlags

* gov tx

* Fix compiler errors

* Formatting

* x/distribution: use gRPC query

* Consistent

* Fix x/distrib test

* Update x/gov

* Add ReadQueryCommandFlags

* Fix lint

* Revert x/params

* x/params use grpc query

* Fix tests

* Use page request

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Amaury Martiny 2020-07-20 15:09:57 +02:00 committed by GitHub
parent 1d6344888e
commit 8e61ef86c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 381 additions and 338 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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.

View File

@ -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

View File

@ -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, &params); 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])
validatorAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}
params := types.NewQueryValidatorOutstandingRewardsParams(valAddr)
bz, err := clientCtx.JSONMarshaler.MarshalJSON(params)
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)
pageReq := client.ReadPageRequest(cmd.Flags())
res, err := queryClient.ValidatorSlashes(
context.Background(),
&types.QueryValidatorSlashesRequest{
ValidatorAddress: validatorAddr,
StartingHeight: startHeight,
EndingHeight: endHeight,
Req: pageReq,
},
)
if err != nil {
return err
}
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_slashes", types.QuerierRoute), bz)
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
}
// query for rewards from a particular delegation
if len(args) == 2 {
resp, _, err := common.QueryDelegationRewards(clientCtx, args[0], 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)
}
return clientCtx.PrintOutput(result)
}
queryClient := types.NewQueryClient(clientCtx)
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)
// query for rewards from a particular delegation
if len(args) == 2 {
validatorAddr, err := sdk.ValAddressFromBech32(args[1])
if err != nil {
return err
}
res, err := queryClient.DelegationRewards(
context.Background(),
&types.QueryDelegationRewardsRequest{DelegatorAddress: delegatorAddr, ValidatorAddress: validatorAddr},
)
if err != nil {
return 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())
},
}

View File

@ -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)
}

View File

@ -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.

View File

@ -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")

View File

@ -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
}
if len(strProposalStatus) != 0 {
proposalStatus, err := types.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus))
if err != nil {
return err
}
params.ProposalStatus = proposalStatus
}
bz, err := cdc.MarshalJSON(params)
depositorAddr, err := sdk.AccAddressFromBech32(bechDepositorAddr)
if err != nil {
return err
}
clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc)
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz)
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
if err != nil {
return err
}
var matchingProposals types.Proposals
err = cdc.UnmarshalJSON(res, &matchingProposals)
proposalStatus, err := types.ProposalStatusFromString(gcutils.NormalizeProposalStatus(strProposalStatus))
if err != nil {
return err
}
if len(matchingProposals) == 0 {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err = client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
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(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)
res, err := queryClient.Vote(
context.Background(),
&types.QueryVoteRequest{ProposalId: proposalID, Voter: voterAddr},
)
if err != nil {
return err
}
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz)
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)
res, err := queryClient.Deposit(
context.Background(),
&types.QueryDepositRequest{ProposalId: proposalID, Depositor: depositorAddr},
)
if err != nil {
return err
}
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz)
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)
if err != nil {
return err
}
vp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/voting", 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
}
var tallyParams types.TallyParams
cdc.MustUnmarshalJSON(tp, &tallyParams)
var depositParams types.DepositParams
cdc.MustUnmarshalJSON(dp, &depositParams)
var votingParams types.VotingParams
cdc.MustUnmarshalJSON(vp, &votingParams)
tallyRes, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{ParamsType: "tallying"},
)
if err != nil {
return err
}
return clientCtx.PrintOutput(types.NewParams(votingParams, tallyParams, depositParams))
depositRes, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{ParamsType: "deposit"},
)
if err != nil {
return err
}
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)
// Query store
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, args[0]), nil)
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
// Query store
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, &param)
out = param
out = res.GetVotingParams()
case "tallying":
var param types.TallyParams
cdc.MustUnmarshalJSON(res, &param)
out = param
out = res.GetTallyParams()
case "deposit":
var param types.DepositParams
cdc.MustUnmarshalJSON(res, &param)
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)

View File

@ -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()

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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"`,
},
}

View File

@ -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())
},
}

View File

@ -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.

View File

@ -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

View File

@ -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(), &params)
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(), &params)
if err != nil {
return err
}

View File

@ -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

View File

@ -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,
},

View File

@ -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 {

View File

@ -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}
}