-
Notifications
You must be signed in to change notification settings - Fork 206
/
addproposal.go
72 lines (55 loc) · 1.64 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
71
72
package types
import (
fmt "fmt"
"strings"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalSpecAdd = "SpecAdd"
)
var _ govtypes.Content = &SpecAddProposal{}
func init() {
govtypes.RegisterProposalType(ProposalSpecAdd)
}
func NewSpecAddProposal(title, description string, specs []Spec) *SpecAddProposal {
return &SpecAddProposal{title, description, specs}
}
// GetTitle returns the title of a proposal.
func (pcp *SpecAddProposal) GetTitle() string { return pcp.Title }
// GetDescription returns the description of a proposal.
func (pcp *SpecAddProposal) GetDescription() string { return pcp.Description }
// ProposalRoute returns the routing key of a proposal.
func (pcp *SpecAddProposal) ProposalRoute() string { return ProposalsRouterKey }
// ProposalType returns the type of a proposal.
func (pcp *SpecAddProposal) ProposalType() string { return ProposalSpecAdd }
// ValidateBasic validates the proposal
func (pcp *SpecAddProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(pcp)
if err != nil {
return err
}
if len(pcp.Specs) == 0 {
return sdkerrors.Wrap(ErrEmptySpecs, "proposal specs cannot be empty")
}
for _, spec := range pcp.Specs {
err := checkSpecProposal(spec)
if err != nil {
return err
}
}
return nil
}
// String implements the Stringer interface.
func (pcp SpecAddProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Spec Add Proposal:
Title: %s
Description: %s
Changes:
`, pcp.Title, pcp.Description))
for _, spec := range pcp.Specs {
b = stringSpec(spec, b)
}
return b.String()
}