github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/gov/types/content.go (about)

     1  package types
     2  
     3  import (
     4  	"strings"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  )
     8  
     9  // Constants pertaining to a Content object
    10  const (
    11  	MaxDescriptionLength int = 5000
    12  	MaxTitleLength       int = 140
    13  )
    14  
    15  // Content defines an interface that a proposal must implement. It contains
    16  // information such as the title and description along with the type and routing
    17  // information for the appropriate handler to process the proposal. Content can
    18  // have additional fields, which will handled by a proposal's Handler.
    19  type Content interface {
    20  	GetTitle() string
    21  	GetDescription() string
    22  	ProposalRoute() string
    23  	ProposalType() string
    24  	ValidateBasic() sdk.Error
    25  	String() string
    26  }
    27  
    28  // Handler defines a function that handles a proposal after it has passed the
    29  // governance process.
    30  type Handler func(ctx sdk.Context, proposal *Proposal) sdk.Error
    31  
    32  // ValidateAbstract validates a proposal's abstract contents returning an error
    33  // if invalid.
    34  func ValidateAbstract(codespace string, c Content) sdk.Error {
    35  	title := c.GetTitle()
    36  	if len(strings.TrimSpace(title)) == 0 {
    37  		return ErrInvalidProposalContent("title is required")
    38  	}
    39  	if len(title) > MaxTitleLength {
    40  		return ErrInvalidProposalContent("title length is bigger than max title length")
    41  	}
    42  
    43  	description := c.GetDescription()
    44  	if len(description) == 0 {
    45  		return ErrInvalidProposalContent("description is required")
    46  	}
    47  	if len(description) > MaxDescriptionLength {
    48  		return ErrInvalidProposalContent("description length is bigger than max description length")
    49  	}
    50  
    51  	return nil
    52  }