From 4d62e430faec6e01eda3c04c91319cf4a7bc50bc Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Mon, 28 Feb 2022 15:32:08 +0530 Subject: [PATCH 1/2] add flags validation --- x/gov/client/cli/parse.go | 28 ++++++++++++++++++++++++++++ x/gov/client/cli/tx.go | 8 ++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/x/gov/client/cli/parse.go b/x/gov/client/cli/parse.go index 306b4b10dde..91736f98533 100644 --- a/x/gov/client/cli/parse.go +++ b/x/gov/client/cli/parse.go @@ -19,17 +19,41 @@ type legacyProposal struct { Deposit string } +func (p legacyProposal) validate() error { + if p.Type == "" { + return fmt.Errorf("proposal type is required") + } + + if p.Title == "" { + return fmt.Errorf("proposal title is required") + } + + if p.Description == "" { + return fmt.Errorf("proposal description is required") + } + return nil +} + func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error) { proposal := &legacyProposal{} proposalFile, _ := fs.GetString(FlagProposal) if proposalFile == "" { proposalType, _ := fs.GetString(FlagProposalType) + title, _ := fs.GetString(FlagTitle) + description, _ := fs.GetString(FlagDescription) + if proposalType == "" && title == "" && description == "" { + return nil, fmt.Errorf("one of the --proposal or (--title, --description and --type) flags are required") + } proposal.Title, _ = fs.GetString(FlagTitle) proposal.Description, _ = fs.GetString(FlagDescription) proposal.Type = govutils.NormalizeProposalType(proposalType) proposal.Deposit, _ = fs.GetString(FlagDeposit) + if err := proposal.validate(); err != nil { + return nil, err + } + return proposal, nil } @@ -49,6 +73,10 @@ func parseSubmitLegacyProposalFlags(fs *pflag.FlagSet) (*legacyProposal, error) return nil, err } + if err := proposal.validate(); err != nil { + return nil, err + } + return proposal, nil } diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 17c3db75e4e..d23d717fd9b 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -27,10 +27,10 @@ const ( // Deprecated: only used for v1beta1 legacy proposals. FlagProposalType = "type" // Deprecated: only used for v1beta1 legacy proposals. - FlagDeposit = "deposit" - flagVoter = "voter" - flagDepositor = "depositor" - flagStatus = "status" + FlagDeposit = "deposit" + flagVoter = "voter" + flagDepositor = "depositor" + flagStatus = "status" // Deprecated: only used for v1beta1 legacy proposals. FlagProposal = "proposal" ) From c0b17c18d5c26b71a0c832e5b555efcd4e2ab61a Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Mon, 28 Feb 2022 16:50:01 +0530 Subject: [PATCH 2/2] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 668f7e08763..28a3352a0f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [\#11004](https://github.com/cosmos/cosmos-sdk/pull/11004) Added mutable versions of many of the sdk.Dec types operations. This improves performance when used by avoiding reallocating a new bigint for each operation. * (x/auth) [\#10880](https://github.com/cosmos/cosmos-sdk/pull/10880) Added a new query to the tx query service that returns a block with transactions fully decoded. * (types) [\#11200](https://github.com/cosmos/cosmos-sdk/pull/11200) Added `Min()` and `Max()` operations on sdk.Coins. +* (gov) [\#11287](https://github.com/cosmos/cosmos-sdk/pull/11287) Fix error message when no flags are provided while executing `submit-legacy-proposal` transaction. ### Bug Fixes