github.com/Finschia/finschia-sdk@v0.48.1/x/params/client/cli/tx.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/spf13/cobra"
     8  
     9  	"github.com/Finschia/finschia-sdk/client"
    10  	"github.com/Finschia/finschia-sdk/client/tx"
    11  	sdk "github.com/Finschia/finschia-sdk/types"
    12  	"github.com/Finschia/finschia-sdk/version"
    13  	govtypes "github.com/Finschia/finschia-sdk/x/gov/types"
    14  	paramscutils "github.com/Finschia/finschia-sdk/x/params/client/utils"
    15  	paramproposal "github.com/Finschia/finschia-sdk/x/params/types/proposal"
    16  )
    17  
    18  // NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating
    19  // a parameter change proposal governance transaction.
    20  func NewSubmitParamChangeProposalTxCmd() *cobra.Command {
    21  	return &cobra.Command{
    22  		Use:   "param-change [proposal-file]",
    23  		Args:  cobra.ExactArgs(1),
    24  		Short: "Submit a parameter change proposal",
    25  		Long: strings.TrimSpace(
    26  			fmt.Sprintf(`Submit a parameter proposal along with an initial deposit.
    27  The proposal details must be supplied via a JSON file. For values that contains
    28  objects, only non-empty fields will be updated.
    29  
    30  IMPORTANT: Currently parameter changes are evaluated but not validated, so it is
    31  very important that any "value" change is valid (ie. correct type and within bounds)
    32  for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal.
    33  
    34  Proper vetting of a parameter change proposal should prevent this from happening
    35  (no deposits should occur during the governance process), but it should be noted
    36  regardless.
    37  
    38  Example:
    39  $ %s tx gov submit-proposal param-change <path/to/proposal.json> --from=<key_or_address>
    40  
    41  Where proposal.json contains:
    42  
    43  {
    44    "title": "Staking Param Change",
    45    "description": "Update max validators",
    46    "changes": [
    47      {
    48        "subspace": "staking",
    49        "key": "MaxValidators",
    50        "value": 105
    51      }
    52    ],
    53    "deposit": "1000stake"
    54  }
    55  `,
    56  				version.AppName,
    57  			),
    58  		),
    59  		RunE: func(cmd *cobra.Command, args []string) error {
    60  			clientCtx, err := client.GetClientTxContext(cmd)
    61  			if err != nil {
    62  				return err
    63  			}
    64  			proposal, err := paramscutils.ParseParamChangeProposalJSON(clientCtx.LegacyAmino, args[0])
    65  			if err != nil {
    66  				return err
    67  			}
    68  
    69  			from := clientCtx.GetFromAddress()
    70  			content := paramproposal.NewParameterChangeProposal(
    71  				proposal.Title, proposal.Description, proposal.Changes.ToParamChanges(),
    72  			)
    73  
    74  			deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
    75  			if err != nil {
    76  				return err
    77  			}
    78  
    79  			msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
    80  			if err != nil {
    81  				return err
    82  			}
    83  
    84  			return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
    85  		},
    86  	}
    87  }