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!: have tx gov submit-proposal accept either new or legacy syntax #378

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG-Agoric.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
98 changes: 45 additions & 53 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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{
Expand Down
Loading