/
gov.go
73 lines (59 loc) · 1.92 KB
/
gov.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
73
package types
import (
"fmt"
"strings"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalTypeCreateGroups = "CreateGroups"
)
func init() {
govtypes.RegisterProposalType(ProposalTypeCreateGroups)
govtypes.RegisterProposalTypeCodec(&CreateGroupsProposal{}, "furya/CreateGroupsProposal")
}
var (
_ govtypes.Content = &CreateGroupsProposal{}
)
// NewCreateGroupsProposal returns a new instance of a group creation proposal struct.
func NewCreateGroupsProposal(title, description string, groups []CreateGroup) govtypes.Content {
return &CreateGroupsProposal{
Title: title,
Description: description,
CreateGroups: groups,
}
}
func (p *CreateGroupsProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *CreateGroupsProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *CreateGroupsProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *CreateGroupsProposal) ProposalType() string {
return ProposalTypeCreateGroups
}
// ValidateBasic validates a governance proposal's abstract and basic contents
func (p *CreateGroupsProposal) ValidateBasic() error {
if len(p.CreateGroups) == 0 {
return fmt.Errorf("must provide at least one group")
}
for _, group := range p.CreateGroups {
if len(group.PoolIds) <= 1 {
return fmt.Errorf("each group much be comprised of at least two pool ids")
}
}
return nil
}
// String returns a string to display the proposal.
func (p CreateGroupsProposal) String() string {
recordsStr := ""
for _, group := range p.CreateGroups {
recordsStr = recordsStr + fmt.Sprintf("(PoolIDs: %d) ", group.PoolIds)
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Create Groups Proposal:
Title: %s
Description: %s
Groups: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}