Skip to content

Commit 77b8834

Browse files
committed
feat: add param change proposal tx cli
1 parent 5643727 commit 77b8834

File tree

1 file changed

+79
-0
lines changed
  • x/tokenfactory/client/cli

1 file changed

+79
-0
lines changed

x/tokenfactory/client/cli/tx.go

+79
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414

1515
"github.com/CosmWasm/wasmd/x/tokenfactory/types"
1616
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
17+
18+
"github.com/cosmos/cosmos-sdk/version"
19+
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
20+
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
21+
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
1722
)
1823

1924
// GetTxCmd returns the transaction commands for this module
@@ -35,6 +40,7 @@ func GetTxCmd() *cobra.Command {
3540
NewForceTransferCmd(),
3641
NewChangeAdminCmd(),
3742
NewModifyDenomMetadataCmd(),
43+
NewSubmitParamChangeProposalTxCmd(),
3844
)
3945

4046
return cmd
@@ -379,3 +385,76 @@ func NewModifyDenomMetadataCmd() *cobra.Command {
379385
flags.AddTxFlagsToCmd(cmd)
380386
return cmd
381387
}
388+
389+
// NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating
390+
// a parameter change proposal governance transaction.
391+
func NewSubmitParamChangeProposalTxCmd() *cobra.Command {
392+
cmd := &cobra.Command{
393+
Use: "param-change [proposal-file]",
394+
Args: cobra.ExactArgs(1),
395+
Short: "Submit a parameter change proposal",
396+
Long: strings.TrimSpace(
397+
fmt.Sprintf(`Submit a parameter proposal along with an initial deposit.
398+
The proposal details must be supplied via a JSON file. For values that contains
399+
objects, only non-empty fields will be updated.
400+
401+
IMPORTANT: Currently parameter changes are evaluated but not validated, so it is
402+
very important that any "value" change is valid (ie. correct type and within bounds)
403+
for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal.
404+
405+
Proper vetting of a parameter change proposal should prevent this from happening
406+
(no deposits should occur during the governance process), but it should be noted
407+
regardless.
408+
409+
Example:
410+
$ %s tx gov submit-proposal param-change <path/to/proposal.json> --from=<key_or_address>
411+
412+
Where proposal.json contains:
413+
414+
{
415+
"title": "Staking Param Change",
416+
"description": "Update max validators",
417+
"changes": [
418+
{
419+
"subspace": "staking",
420+
"key": "MaxValidators",
421+
"value": 105
422+
}
423+
],
424+
"deposit": "1000stake"
425+
}
426+
`,
427+
version.AppName,
428+
),
429+
),
430+
RunE: func(cmd *cobra.Command, args []string) error {
431+
clientCtx, err := client.GetClientTxContext(cmd)
432+
if err != nil {
433+
return err
434+
}
435+
proposal, err := paramscutils.ParseParamChangeProposalJSON(clientCtx.LegacyAmino, args[0])
436+
if err != nil {
437+
return err
438+
}
439+
440+
from := clientCtx.GetFromAddress()
441+
content := paramproposal.NewParameterChangeProposal(
442+
proposal.Title, proposal.Description, proposal.Changes.ToParamChanges(),
443+
)
444+
445+
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
446+
if err != nil {
447+
return err
448+
}
449+
450+
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from)
451+
if err != nil {
452+
return err
453+
}
454+
455+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
456+
},
457+
}
458+
flags.AddTxFlagsToCmd(cmd)
459+
return cmd
460+
}

0 commit comments

Comments
 (0)