-
Notifications
You must be signed in to change notification settings - Fork 557
/
gov.go
125 lines (100 loc) · 3.35 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
package types
import (
"fmt"
"strings"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalTypeUpdatePoolIncentives = "UpdatePoolIncentives"
ProposalTypeReplacePoolIncentives = "ReplacePoolIncentives"
)
func init() {
govtypes.RegisterProposalType(ProposalTypeUpdatePoolIncentives)
govtypes.RegisterProposalTypeCodec(&UpdatePoolIncentivesProposal{}, "osmosis/UpdatePoolIncentivesProposal")
govtypes.RegisterProposalType(ProposalTypeReplacePoolIncentives)
govtypes.RegisterProposalTypeCodec(&ReplacePoolIncentivesProposal{}, "osmosis/ReplacePoolIncentivesProposal")
}
var _ govtypes.Content = &UpdatePoolIncentivesProposal{}
var _ govtypes.Content = &ReplacePoolIncentivesProposal{}
func NewReplacePoolIncentivesProposal(title, description string, records []DistrRecord) govtypes.Content {
return &ReplacePoolIncentivesProposal{
Title: title,
Description: description,
Records: records,
}
}
func (p *ReplacePoolIncentivesProposal) GetTitle() string { return p.Title }
func (p *ReplacePoolIncentivesProposal) GetDescription() string { return p.Description }
func (p *ReplacePoolIncentivesProposal) ProposalRoute() string { return RouterKey }
func (p *ReplacePoolIncentivesProposal) ProposalType() string {
return ProposalTypeUpdatePoolIncentives
}
func (p *ReplacePoolIncentivesProposal) ValidateBasic() error {
err := govtypes.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
}
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()
}
func NewUpdatePoolIncentivesProposal(title, description string, records []DistrRecord) govtypes.Content {
return &UpdatePoolIncentivesProposal{
Title: title,
Description: description,
Records: records,
}
}
func (p *UpdatePoolIncentivesProposal) GetTitle() string { return p.Title }
func (p *UpdatePoolIncentivesProposal) GetDescription() string { return p.Description }
func (p *UpdatePoolIncentivesProposal) ProposalRoute() string { return RouterKey }
func (p *UpdatePoolIncentivesProposal) ProposalType() string { return ProposalTypeUpdatePoolIncentives }
func (p *UpdatePoolIncentivesProposal) ValidateBasic() error {
err := govtypes.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
}
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()
}