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