github.com/Finschia/finschia-sdk@v0.48.1/x/gov/types/content.go (about) 1 package types 2 3 import ( 4 "strings" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 8 ) 9 10 // Constants pertaining to a Content object 11 const ( 12 MaxDescriptionLength int = 10000 13 MaxTitleLength int = 140 14 ) 15 16 // Content defines an interface that a proposal must implement. It contains 17 // information such as the title and description along with the type and routing 18 // information for the appropriate handler to process the proposal. Content can 19 // have additional fields, which will handled by a proposal's Handler. 20 // TODO Try to unify this interface with types/module/simulation 21 // https://github.com/cosmos/cosmos-sdk/issues/5853 22 type Content interface { 23 GetTitle() string 24 GetDescription() string 25 ProposalRoute() string 26 ProposalType() string 27 ValidateBasic() error 28 String() string 29 } 30 31 // Handler defines a function that handles a proposal after it has passed the 32 // governance process. 33 type Handler func(ctx sdk.Context, content Content) error 34 35 // ValidateAbstract validates a proposal's abstract contents returning an error 36 // if invalid. 37 func ValidateAbstract(c Content) error { 38 title := c.GetTitle() 39 if len(strings.TrimSpace(title)) == 0 { 40 return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal title cannot be blank") 41 } 42 if len(title) > MaxTitleLength { 43 return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength) 44 } 45 46 description := c.GetDescription() 47 if len(description) == 0 { 48 return sdkerrors.Wrap(ErrInvalidProposalContent, "proposal description cannot be blank") 49 } 50 if len(description) > MaxDescriptionLength { 51 return sdkerrors.Wrapf(ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength) 52 } 53 54 return nil 55 }