github.com/cosmos/cosmos-sdk@v0.50.10/x/params/types/proposal/proposal.go (about)

     1  package proposal
     2  
     3  import (
     4  	govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
     5  )
     6  
     7  const (
     8  	// ProposalTypeChange defines the type for a ParameterChangeProposal
     9  	ProposalTypeChange = "ParameterChange"
    10  )
    11  
    12  // Assert ParameterChangeProposal implements govtypes.Content at compile-time
    13  var _ govtypes.Content = &ParameterChangeProposal{}
    14  
    15  func init() {
    16  	govtypes.RegisterProposalType(ProposalTypeChange)
    17  }
    18  
    19  func NewParameterChangeProposal(title, description string, changes []ParamChange) *ParameterChangeProposal {
    20  	return &ParameterChangeProposal{title, description, changes}
    21  }
    22  
    23  // GetTitle returns the title of a parameter change proposal.
    24  func (pcp *ParameterChangeProposal) GetTitle() string { return pcp.Title }
    25  
    26  // GetDescription returns the description of a parameter change proposal.
    27  func (pcp *ParameterChangeProposal) GetDescription() string { return pcp.Description }
    28  
    29  // ProposalRoute returns the routing key of a parameter change proposal.
    30  func (pcp *ParameterChangeProposal) ProposalRoute() string { return RouterKey }
    31  
    32  // ProposalType returns the type of a parameter change proposal.
    33  func (pcp *ParameterChangeProposal) ProposalType() string { return ProposalTypeChange }
    34  
    35  // ValidateBasic validates the parameter change proposal
    36  func (pcp *ParameterChangeProposal) ValidateBasic() error {
    37  	err := govtypes.ValidateAbstract(pcp)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	return ValidateChanges(pcp.Changes)
    43  }
    44  
    45  func NewParamChange(subspace, key, value string) ParamChange {
    46  	return ParamChange{subspace, key, value}
    47  }
    48  
    49  // ValidateChanges performs basic validation checks over a set of ParamChange. It
    50  // returns an error if any ParamChange is invalid.
    51  func ValidateChanges(changes []ParamChange) error {
    52  	if len(changes) == 0 {
    53  		return ErrEmptyChanges
    54  	}
    55  
    56  	for _, pc := range changes {
    57  		if len(pc.Subspace) == 0 {
    58  			return ErrEmptySubspace
    59  		}
    60  		if len(pc.Key) == 0 {
    61  			return ErrEmptyKey
    62  		}
    63  		if len(pc.Value) == 0 {
    64  			return ErrEmptyValue
    65  		}
    66  	}
    67  
    68  	return nil
    69  }