Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gov,cli): Create AddGovPropFlagsToCmd and ReadGovPropFlags. (backport #14718) #15471

Merged
merged 5 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#13210](https://github.com/cosmos/cosmos-sdk/pull/13210) Add `Query/AccountInfo` endpoint for simplified access to basic account info.
* (x/consensus) [#12905](https://github.com/cosmos/cosmos-sdk/pull/12905) Create a new `x/consensus` module that is now responsible for maintaining Tendermint consensus parameters instead of `x/param`. Legacy types remain in order to facilitate parameter migration from the deprecated `x/params`. App developers should ensure that they execute `baseapp.MigrateParams` during their chain upgrade. These legacy types will be removed in a future release.
* (client/tx) [#13670](https://github.com/cosmos/cosmos-sdk/pull/13670) Add validation in `BuildUnsignedTx` to prevent simple inclusion of valid mnemonics
<<<<<<< HEAD
=======
* [#13473](https://github.com/cosmos/cosmos-sdk/pull/13473) ADR-038: Go plugin system proposal
* [#14356](https://github.com/cosmos/cosmos-sdk/pull/14356) Add `events.GetAttributes` and `event.GetAttribute` methods to simplify the retrieval of an attribute from event(s).
* [#14472](https://github.com/cosmos/cosmos-sdk/pull/14356) The recommended metadata format for x/gov and x/group proposals now uses an array of strings (instead of a single string) for the `authors` field.
* (mempool) [#14484](https://github.com/cosmos/cosmos-sdk/pull/14484) Add priority nonce mempool option for transaction replacement.
* (client) [#14509](https://github.com/cosmos/cosmos-sdk/pull/#14509) Added `AddKeyringFlags` function.
* (x/gov,cli) [#14718](https://github.com/cosmos/cosmos-sdk/pull/14718) Added `AddGovPropFlagsToCmd` and `ReadGovPropFlags` functions.
>>>>>>> 667440221 (feat(gov,cli): Create AddGovPropFlagsToCmd and ReadGovPropFlags. (#14718))

### Improvements

Expand Down
5 changes: 5 additions & 0 deletions x/feegrant/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,13 @@ func (s *CLITestSuite) msgSubmitLegacyProposal(clientCtx client.Context, from, t

args := append([]string{
fmt.Sprintf("--%s=%s", govcli.FlagTitle, title),
<<<<<<< HEAD
fmt.Sprintf("--%s=%s", govcli.FlagDescription, description),
fmt.Sprintf("--%s=%s", govcli.FlagProposalType, proposalType),
=======
fmt.Sprintf("--%s=%s", govcli.FlagDescription, description), //nolint:staticcheck // SA1019: govcli.FlagDescription is deprecated: use FlagDescription instead
fmt.Sprintf("--%s=%s", govcli.FlagProposalType, proposalType), //nolint:staticcheck // SA1019: govcli.FlagProposalType is deprecated: use FlagProposalType instead
>>>>>>> 667440221 (feat(gov,cli): Create AddGovPropFlagsToCmd and ReadGovPropFlags. (#14718))
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}, commonArgs...)

Expand Down
12 changes: 6 additions & 6 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

// Proposal flags
const (
// Deprecated: only used for v1beta1 legacy proposals.
FlagTitle = "title"
// Deprecated: only used for v1beta1 legacy proposals.
FlagDescription = "description"
Expand All @@ -30,7 +29,8 @@ const (
flagVoter = "voter"
flagDepositor = "depositor"
flagStatus = "status"
flagMetadata = "metadata"
FlagMetadata = "metadata"
FlagSummary = "summary"
// Deprecated: only used for v1beta1 legacy proposals.
FlagProposal = "proposal"
)
Expand Down Expand Up @@ -303,7 +303,7 @@ $ %s tx gov vote 1 yes --from mykey
return err
}

metadata, err := cmd.Flags().GetString(flagMetadata)
metadata, err := cmd.Flags().GetString(FlagMetadata)
if err != nil {
return err
}
Expand All @@ -315,7 +315,7 @@ $ %s tx gov vote 1 yes --from mykey
},
}

cmd.Flags().String(flagMetadata, "", "Specify metadata of the vote")
cmd.Flags().String(FlagMetadata, "", "Specify metadata of the vote")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -358,7 +358,7 @@ $ %s tx gov weighted-vote 1 yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05 --from
return err
}

metadata, err := cmd.Flags().GetString(flagMetadata)
metadata, err := cmd.Flags().GetString(FlagMetadata)
if err != nil {
return err
}
Expand All @@ -369,7 +369,7 @@ $ %s tx gov weighted-vote 1 yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05 --from
},
}

cmd.Flags().String(flagMetadata, "", "Specify metadata of the weighted vote")
cmd.Flags().String(FlagMetadata, "", "Specify metadata of the weighted vote")
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down
51 changes: 51 additions & 0 deletions x/gov/client/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

type legacyProposal struct {
Expand Down Expand Up @@ -118,3 +121,51 @@ func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, string, strin

return msgs, proposal.Metadata, proposal.Title, proposal.Summary, deposit, nil
}

// AddGovPropFlagsToCmd adds flags for defining MsgSubmitProposal fields.
//
// See also ReadGovPropFlags.
func AddGovPropFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().String(FlagDeposit, "", "The deposit to include with the governance proposal")
cmd.Flags().String(FlagMetadata, "", "The metadata to include with the governance proposal")
cmd.Flags().String(FlagTitle, "", "The title to put on the governance proposal")
cmd.Flags().String(FlagSummary, "", "The summary to include with the governance proposal")
}

// ReadGovPropFlags parses a MsgSubmitProposal from the provided context and flags.
// Setting the messages is up to the caller.
//
// See also AddGovPropFlagsToCmd.
func ReadGovPropFlags(clientCtx client.Context, flagSet *pflag.FlagSet) (*govv1.MsgSubmitProposal, error) {
rv := &govv1.MsgSubmitProposal{}

deposit, err := flagSet.GetString(FlagDeposit)
if err != nil {
return nil, fmt.Errorf("could not read deposit: %w", err)
}
if len(deposit) > 0 {
rv.InitialDeposit, err = sdk.ParseCoinsNormalized(deposit)
if err != nil {
return nil, fmt.Errorf("invalid deposit: %w", err)
}
}

rv.Metadata, err = flagSet.GetString(FlagMetadata)
if err != nil {
return nil, fmt.Errorf("could not read metadata: %w", err)
}

rv.Title, err = flagSet.GetString(FlagTitle)
if err != nil {
return nil, fmt.Errorf("could not read title: %w", err)
}

rv.Summary, err = flagSet.GetString(FlagSummary)
if err != nil {
return nil, fmt.Errorf("could not read summary: %w", err)
}

rv.Proposer = clientCtx.GetFromAddress().String()

return rv, nil
}
Loading