Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
445f10d497
commit
2b42efcfc0
@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add a `shutdown-grace` flag for waiting a given time before exit.
|
||||
|
||||
### Improvements
|
||||
|
||||
* (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve `<appd> q gov proposer` by querying directly a proposal instead of tx events. It is an alias of `q gov proposal` as the proposer is a field of the proposal.
|
||||
|
||||
## [v0.50.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.1) - 2023-11-07
|
||||
|
||||
> v0.50.0 has been retracted due to a mistake in tagging the release. Please use v0.50.1 instead.
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
)
|
||||
|
||||
func (s *E2ETestSuite) TestCmdProposer() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
"without proposal id",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
},
|
||||
true,
|
||||
``,
|
||||
},
|
||||
{
|
||||
"json output",
|
||||
[]string{
|
||||
"1",
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
},
|
||||
false,
|
||||
fmt.Sprintf("{\"proposal_id\":%d,\"proposer\":\"%s\"}", 1, val.Address.String()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetCmdQueryProposer()
|
||||
clientCtx := val.ClientCtx
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(strings.TrimSpace(tc.expectedOutput), strings.TrimSpace(out.String()))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -33,6 +33,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
{
|
||||
RpcMethod: "Proposal",
|
||||
Use: "proposal [proposal-id]",
|
||||
Alias: []string{"proposer"},
|
||||
Short: "Query details of a single proposal",
|
||||
Example: fmt.Sprintf("%s query gov proposal 1", version.AppName),
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
// GetCustomQueryCmd returns the cli query commands for this module
|
||||
// These commands do not rely on gRPC and cannot be autogenerated
|
||||
func GetCustomQueryCmd(ac address.Codec) *cobra.Command {
|
||||
// Group gov queries under a subcommand
|
||||
govQueryCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the gov module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
govQueryCmd.AddCommand(
|
||||
GetCmdQueryProposer(),
|
||||
)
|
||||
|
||||
return govQueryCmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposer implements the query proposer command.
|
||||
func GetCmdQueryProposer() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposer [proposal-id]",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Short: "Query the proposer of a governance proposal",
|
||||
Long: "Query which address proposed a proposal with a given ID",
|
||||
Example: fmt.Sprintf("%s query gov proposer 1", version.AppName),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// validate that the proposalID is a uint
|
||||
proposalID, err := strconv.ParseUint(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("proposal-id %s is not a valid uint", args[0])
|
||||
}
|
||||
|
||||
prop, err := gcutils.QueryProposerByTxQuery(clientCtx, proposalID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
output, err := json.Marshal(prop)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return clientCtx.PrintRaw(output)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddQueryFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -161,6 +161,7 @@ func QueryVoteByTxQuery(clientCtx client.Context, params v1.QueryVoteParams) ([]
|
||||
}
|
||||
|
||||
// QueryProposerByTxQuery will query for a proposer of a governance proposal by ID.
|
||||
// Deprecated: Should not be used, as not always accurate. It will be removed in v0.51.
|
||||
func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Proposer, error) {
|
||||
q := fmt.Sprintf("%s.%s='%d'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, proposalID)
|
||||
searchResult, err := authtx.QueryTxsByEvents(clientCtx, defaultPage, defaultLimit, q, "")
|
||||
|
||||
@ -107,12 +107,6 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.NewTxCmd(legacyProposalCLIHandlers)
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the custom query commands for the gov modules.
|
||||
// This command will be enhanced by AutoCLI as defined in the AutoCLIOptions() method.
|
||||
func (ab AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
return cli.GetCustomQueryCmd(ab.ac)
|
||||
}
|
||||
|
||||
func getProposalCLIHandlers(handlers []govclient.ProposalHandler) []*cobra.Command {
|
||||
proposalCLIHandlers := make([]*cobra.Command, 0, len(handlers))
|
||||
for _, proposalHandler := range handlers {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user