-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposal_distr_proposal.go
199 lines (159 loc) · 7.13 KB
/
proposal_distr_proposal.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package types
import (
"fmt"
"strings"
sdk "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
"github.com/evoblockchain/evochain/libs/tendermint/global"
"github.com/evoblockchain/evochain/libs/tendermint/types"
govtypes "github.com/evoblockchain/evochain/x/gov/types"
)
const (
// ProposalTypeChangeDistributionType defines the type for a ChangeDistributionTypeProposal
ProposalTypeChangeDistributionType = "ChangeDistributionType"
// ProposalTypeWithdrawRewardEnabled defines the type for a WithdrawRewardEnabledProposal
ProposalTypeWithdrawRewardEnabled = "WithdrawRewardEnabled"
// ProposalTypeRewardTruncatePrecision defines the type for a RewardTruncatePrecision
ProposalTypeRewardTruncatePrecision = "RewardTruncatePrecision"
)
const (
DistributionTypeOffChain uint32 = 0
DistributionTypeOnChain uint32 = 1
)
// Assert ChangeDistributionTypeProposal implements govtypes.Content at compile-time
var _ govtypes.Content = ChangeDistributionTypeProposal{}
// ChangeDistributionTypeProposal
type ChangeDistributionTypeProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Type uint32 `json:"type" yaml:"type"`
}
// NewChangeDistributionTypeProposal creates a new change distribution type proposal.
func NewChangeDistributionTypeProposal(title, description string, distrType uint32) ChangeDistributionTypeProposal {
return ChangeDistributionTypeProposal{title, description, distrType}
}
// GetTitle returns the title of a change distribution type proposal.
func (cdtp ChangeDistributionTypeProposal) GetTitle() string { return cdtp.Title }
// GetDescription returns the description of a change distribution type proposal.
func (cdtp ChangeDistributionTypeProposal) GetDescription() string { return cdtp.Description }
// GetDescription returns the routing key of a change distribution type proposal.
func (cdtp ChangeDistributionTypeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a change distribution type proposal.
func (cdtp ChangeDistributionTypeProposal) ProposalType() string {
return ProposalTypeChangeDistributionType
}
// ValidateBasic runs basic stateless validity checks
func (cdtp ChangeDistributionTypeProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(ModuleName, cdtp)
if err != nil {
return err
}
if cdtp.Type != DistributionTypeOffChain && cdtp.Type != DistributionTypeOnChain {
return ErrInvalidDistributionType()
}
//will delete it after upgrade venus2
if !types.HigherThanVenus2(global.GetGlobalHeight()) {
return ErrCodeNotSupportDistributionProposal()
}
return nil
}
// String implements the Stringer interface.
func (cdtp ChangeDistributionTypeProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Change Distribution Type Proposal:
Title: %s
Description: %s
Type: %d
`, cdtp.Title, cdtp.Description, cdtp.Type))
return b.String()
}
// Assert WithdrawRewardEnabledProposal implements govtypes.Content at compile-time
var _ govtypes.Content = WithdrawRewardEnabledProposal{}
// WithdrawRewardEnabledProposal
type WithdrawRewardEnabledProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Enabled bool `json:"enabled" yaml:"enabled"`
}
// NewWithdrawRewardEnabledProposal creates a set withdraw reward enabled proposal.
func NewWithdrawRewardEnabledProposal(title, description string, enable bool) WithdrawRewardEnabledProposal {
return WithdrawRewardEnabledProposal{title, description, enable}
}
// GetTitle returns the title of a set withdraw reward enabled proposal.
func (proposal WithdrawRewardEnabledProposal) GetTitle() string { return proposal.Title }
// GetDescription returns the description of a set withdraw reward enabled proposal.
func (proposal WithdrawRewardEnabledProposal) GetDescription() string { return proposal.Description }
// GetDescription returns the routing key of a set withdraw reward enabled proposal.
func (proposal WithdrawRewardEnabledProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a set withdraw reward enabled proposal.
func (proposal WithdrawRewardEnabledProposal) ProposalType() string {
return ProposalTypeWithdrawRewardEnabled
}
// ValidateBasic runs basic stateless validity checks
func (proposal WithdrawRewardEnabledProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(ModuleName, proposal)
if err != nil {
return err
}
//will delete it after upgrade venus2
if !types.HigherThanVenus2(global.GetGlobalHeight()) {
return ErrCodeNotSupportWithdrawRewardEnabledProposal()
}
return nil
}
// String implements the Stringer interface.
func (proposal WithdrawRewardEnabledProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Withdraw Reward Enabled Proposal:
Title: %s
Description: %s
Enabled: %t
`, proposal.Title, proposal.Description, proposal.Enabled))
return b.String()
}
// Assert RewardTruncatePrecisionProposal implements govtypes.Content at compile-time
var _ govtypes.Content = RewardTruncatePrecisionProposal{}
// RewardTruncatePrecisionProposal
type RewardTruncatePrecisionProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Precision int64 `json:"precision" yaml:"precision"`
}
// NewRewardTruncatePrecisionProposal creates a reward truncate precision proposal.
func NewRewardTruncatePrecisionProposal(title, description string, precision int64) RewardTruncatePrecisionProposal {
return RewardTruncatePrecisionProposal{title, description, precision}
}
// GetTitle returns the title of a set withdraw reward enabled proposal.
func (proposal RewardTruncatePrecisionProposal) GetTitle() string { return proposal.Title }
// GetDescription returns the description of a set withdraw reward enabled proposal.
func (proposal RewardTruncatePrecisionProposal) GetDescription() string { return proposal.Description }
// GetDescription returns the routing key of a set withdraw reward enabled proposal.
func (proposal RewardTruncatePrecisionProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a set withdraw reward enabled proposal.
func (proposal RewardTruncatePrecisionProposal) ProposalType() string {
return ProposalTypeRewardTruncatePrecision
}
// ValidateBasic runs basic stateless validity checks
func (proposal RewardTruncatePrecisionProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(ModuleName, proposal)
if err != nil {
return err
}
if proposal.Precision < 0 || proposal.Precision > sdk.Precision {
return ErrCodeRewardTruncatePrecision()
}
//will delete it after upgrade venus2
if !types.HigherThanVenus2(global.GetGlobalHeight()) {
return ErrCodeNotSupportRewardTruncateProposal()
}
return nil
}
// String implements the Stringer interface.
func (proposal RewardTruncatePrecisionProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Reward Truncate Precision Proposal:
Title: %s
Description: %s
Precision: %d
`, proposal.Title, proposal.Description, proposal.Precision))
return b.String()
}