-
Notifications
You must be signed in to change notification settings - Fork 568
/
gov.go
140 lines (115 loc) · 4.12 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package types
import (
"fmt"
"strings"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
const (
ProposalTypeUpdatePoolIncentives = "UpdatePoolIncentives"
ProposalTypeReplacePoolIncentives = "ReplacePoolIncentives"
)
// Init registers proposals to update and replace pool incentives.
func init() {
govtypesv1.RegisterProposalType(ProposalTypeUpdatePoolIncentives)
govtypesv1.RegisterProposalType(ProposalTypeReplacePoolIncentives)
}
var (
_ govtypesv1.Content = &UpdatePoolIncentivesProposal{}
_ govtypesv1.Content = &ReplacePoolIncentivesProposal{}
)
// NewReplacePoolIncentivesProposal returns a new instance of a replace pool incentives proposal struct.
func NewReplacePoolIncentivesProposal(title, description string, records []DistrRecord) govtypesv1.Content {
return &ReplacePoolIncentivesProposal{
Title: title,
Description: description,
Records: records,
}
}
// GetTitle gets the title of the proposal
func (p *ReplacePoolIncentivesProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *ReplacePoolIncentivesProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *ReplacePoolIncentivesProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *ReplacePoolIncentivesProposal) ProposalType() string {
return ProposalTypeReplacePoolIncentives
}
// ValidateBasic validates a governance proposal's abstract and basic contents
func (p *ReplacePoolIncentivesProposal) ValidateBasic() error {
err := govtypesv1.ValidateAbstract(p)
if err != nil {
return err
}
if len(p.Records) == 0 {
return ErrEmptyProposalRecords
}
for _, record := range p.Records {
if err := record.ValidateBasic(); err != nil {
return err
}
}
return nil
}
// String returns a string containing the pool incentives proposal.
func (p ReplacePoolIncentivesProposal) String() string {
// TODO: Make this prettier
recordsStr := ""
for _, record := range p.Records {
recordsStr = recordsStr + fmt.Sprintf("(GaugeId: %d, Weight: %s) ", record.GaugeId, record.Weight.String())
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Replace Pool Incentives Proposal:
Title: %s
Description: %s
Records: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}
// NewReplacePoolIncentivesProposal returns a new instance of a replace pool incentives proposal struct.
func NewUpdatePoolIncentivesProposal(title, description string, records []DistrRecord) govtypesv1.Content {
return &UpdatePoolIncentivesProposal{
Title: title,
Description: description,
Records: records,
}
}
// GetTitle gets the title of the proposal
func (p *UpdatePoolIncentivesProposal) GetTitle() string { return p.Title }
// GetDescription gets the description of the proposal
func (p *UpdatePoolIncentivesProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the router key for the proposal
func (p *UpdatePoolIncentivesProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of the proposal
func (p *UpdatePoolIncentivesProposal) ProposalType() string { return ProposalTypeUpdatePoolIncentives }
// ValidateBasic validates a governance proposal's abstract and basic contents.
func (p *UpdatePoolIncentivesProposal) ValidateBasic() error {
err := govtypesv1.ValidateAbstract(p)
if err != nil {
return err
}
if len(p.Records) == 0 {
return ErrEmptyProposalRecords
}
for _, record := range p.Records {
if err := record.ValidateBasic(); err != nil {
return err
}
}
return nil
}
// String returns a string containing the pool incentives proposal.
func (p UpdatePoolIncentivesProposal) String() string {
// TODO: Make this prettier
recordsStr := ""
for _, record := range p.Records {
recordsStr = recordsStr + fmt.Sprintf("(GaugeId: %d, Weight: %s) ", record.GaugeId, record.Weight.String())
}
var b strings.Builder
b.WriteString(fmt.Sprintf(`Update Pool Incentives Proposal:
Title: %s
Description: %s
Records: %s
`, p.Title, p.Description, recordsStr))
return b.String()
}