diff --git a/CHANGELOG-Agoric.md b/CHANGELOG-Agoric.md index 5b6a7ac1537f..2335f6821f55 100644 --- a/CHANGELOG-Agoric.md +++ b/CHANGELOG-Agoric.md @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog (Agoric fork) +## `v0.46.16-alpha.agoric.2` - 2024-02-08 + +* Agoric/agoric-sdk#8871 Have `tx gov submit-proposal` accept either new or legacy syntax + ## `v0.46.16-alpha.agoric.1` - 2024-02-05 * Agoric/agoric-sdk#8224 Merge [cosmos/cosmos-sdk v0.46.16](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.16) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index f18c14874984..eb8edd5dc05f 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -59,32 +59,34 @@ func NewTxCmd(legacyPropCmds []*cobra.Command) *cobra.Command { RunE: client.ValidateCmd, } - cmdSubmitLegacyProp := NewCmdSubmitLegacyProposal() + cmdSubmitProp := NewCmdSubmitProposal() for _, propCmd := range legacyPropCmds { flags.AddTxFlagsToCmd(propCmd) - cmdSubmitLegacyProp.AddCommand(propCmd) + cmdSubmitProp.AddCommand(propCmd) } govTxCmd.AddCommand( NewCmdDeposit(), NewCmdVote(), NewCmdWeightedVote(), - NewCmdSubmitProposal(), + cmdSubmitProp, NewCmdDraftProposal(), - - // Deprecated - cmdSubmitLegacyProp, ) return govTxCmd } // NewCmdSubmitProposal implements submitting a proposal transaction command. +// NOTE: This command has been modified from its original to subsume both +// the "legacy" and the new (as of v0.46) invocation patterns. This modification +// will be dropped once all legacy call sites have been updated to either +// use the new pattern or call the legacy command explicitly. func NewCmdSubmitProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "submit-proposal [path/to/proposal.json]", - Short: "Submit a proposal along with some messages, metadata and deposit", - Args: cobra.ExactArgs(1), + Use: "submit-proposal [path/to/proposal.json]", + Short: "Submit a proposal along with some messages, metadata and deposit", + Aliases: []string{"submit-legacy-proposal"}, + Args: cobra.MaximumNArgs(1), Long: strings.TrimSpace( fmt.Sprintf(`Submit a proposal along with some messages, metadata and deposit. They should be defined in a JSON file. @@ -107,43 +109,9 @@ Where proposal.json contains: "metadata: "4pIMOgIGx1vZGU=", // base64-encoded metadata "deposit": "10stake" } -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msgs, metadata, deposit, err := parseSubmitProposal(clientCtx.Codec, args[0]) - if err != nil { - return err - } - - msg, err := v1.NewMsgSubmitProposal(msgs, deposit, clientCtx.GetFromAddress().String(), metadata) - if err != nil { - return fmt.Errorf("invalid message: %w", err) - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} -// NewCmdSubmitLegacyProposal implements submitting a proposal transaction command. -// Deprecated: please use NewCmdSubmitProposal instead. -func NewCmdSubmitLegacyProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "submit-legacy-proposal", - Short: "Submit a legacy proposal along with an initial deposit", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a legacy proposal along with an initial deposit. +Legacy Syntax: +Submit a legacy proposal along with an initial deposit. Proposal title, description, type and deposit can be given directly or through a proposal JSON file. Example: @@ -162,7 +130,7 @@ Which is equivalent to: $ %s tx gov submit-legacy-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --deposit="10test" --from mykey `, - version.AppName, version.AppName, + version.AppName, version.AppName, version.AppName, ), ), RunE: func(cmd *cobra.Command, args []string) error { @@ -171,22 +139,39 @@ $ %s tx gov submit-legacy-proposal --title="Test Proposal" --description="My awe return err } + // try to interpret as a legacy submit-proposal call proposal, err := parseSubmitLegacyProposalFlags(cmd.Flags()) - if err != nil { - return fmt.Errorf("failed to parse proposal: %w", err) + if err == nil { + amount, err := sdk.ParseCoinsNormalized(proposal.Deposit) + if err != nil { + return err + } + + content, ok := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) + if !ok { + return fmt.Errorf("failed to create proposal content: unknown proposal type %s", proposal.Type) + } + + msg, err := v1beta1.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress()) + if err != nil { + return fmt.Errorf("invalid message: %w", err) + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } - amount, err := sdk.ParseCoinsNormalized(proposal.Deposit) + // otherwise try to interpret as a new (0.46) submit-proposal + err = cobra.ExactArgs(1)(cmd, args) if err != nil { return err } - content, ok := v1beta1.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) - if !ok { - return fmt.Errorf("failed to create proposal content: unknown proposal type %s", proposal.Type) + msgs, metadata, deposit, err := parseSubmitProposal(clientCtx.Codec, args[0]) + if err != nil { + return err } - msg, err := v1beta1.NewMsgSubmitProposal(content, amount, clientCtx.GetFromAddress()) + msg, err := v1.NewMsgSubmitProposal(msgs, deposit, clientCtx.GetFromAddress().String(), metadata) if err != nil { return fmt.Errorf("invalid message: %w", err) } @@ -205,6 +190,13 @@ $ %s tx gov submit-legacy-proposal --title="Test Proposal" --description="My awe return cmd } +// NewCmdSubmitLegacyProposal implements submitting a proposal transaction command. +// Deprecated: please use NewCmdSubmitProposal instead. +// Preserved for tests. +func NewCmdSubmitLegacyProposal() *cobra.Command { + return NewCmdSubmitProposal() +} + // NewCmdDeposit implements depositing tokens for an active proposal. func NewCmdDeposit() *cobra.Command { cmd := &cobra.Command{