-
Notifications
You must be signed in to change notification settings - Fork 202
/
addproposal.go
70 lines (54 loc) · 1.63 KB
/
addproposal.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package types
import (
fmt "fmt"
"strings"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalPlansAdd = "PlansAdd"
)
func init() {
govtypes.RegisterProposalType(ProposalPlansAdd)
}
func NewPlansAddProposal(title, description string, plans []Plan) *PlansAddProposal {
return &PlansAddProposal{title, description, plans}
}
// GetTitle returns the title of a proposal.
func (pcp *PlansAddProposal) GetTitle() string { return pcp.Title }
// GetDescription returns the description of a proposal.
func (pcp *PlansAddProposal) GetDescription() string { return pcp.Description }
// ProposalRoute returns the routing key of a proposal.
func (pcp *PlansAddProposal) ProposalRoute() string { return ProposalsRouterKey }
// ProposalType returns the type of a proposal.
func (pcp *PlansAddProposal) ProposalType() string { return ProposalPlansAdd }
// ValidateBasic validates the proposal
func (pcp *PlansAddProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(pcp)
if err != nil {
return err
}
if len(pcp.Plans) == 0 {
return sdkerrors.Wrap(ErrEmptyPlans, "proposal plans add cannot be empty")
}
for _, planElem := range pcp.Plans {
err := planElem.ValidatePlan()
if err != nil {
return err
}
}
return nil
}
// String implements the Stringer interface.
func (pcp PlansAddProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Plan Add Proposal:
Title: %s
Description: %s
Changes:
`, pcp.Title, pcp.Description))
for _, planElem := range pcp.Plans {
b.WriteString(planElem.String())
}
return b.String()
}