forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gov.go
280 lines (247 loc) · 7.79 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package types
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalStatusInvalid = "PROPOSAL_STATUS_INVALID"
ProposalStatusPassed = "PROPOSAL_STATUS_PASSED"
)
// DepositParams contains the data of the deposit parameters of the x/gov module
type DepositParams struct {
MinDeposit sdk.Coins `json:"min_deposit,omitempty" yaml:"min_deposit"`
MaxDepositPeriod int64 `json:"max_deposit_period,omitempty" yaml:"max_deposit_period"`
}
// NewDepositParam allows to build a new DepositParams
func NewDepositParam(d govtypes.DepositParams) DepositParams {
return DepositParams{
MinDeposit: d.MinDeposit,
MaxDepositPeriod: d.MaxDepositPeriod.Nanoseconds(),
}
}
// VotingParams contains the voting parameters of the x/gov module
type VotingParams struct {
VotingPeriod int64 `json:"voting_period,omitempty" yaml:"voting_period"`
}
// NewVotingParams allows to build a new VotingParams instance
func NewVotingParams(v govtypes.VotingParams) VotingParams {
return VotingParams{
VotingPeriod: v.VotingPeriod.Nanoseconds(),
}
}
// GovParams contains the data of the x/gov module parameters
type GovParams struct {
DepositParams DepositParams `json:"deposit_params" yaml:"deposit_params"`
VotingParams VotingParams `json:"voting_params" yaml:"voting_params"`
TallyParams TallyParams `json:"tally_params" yaml:"tally_params"`
Height int64 `json:"height" ymal:"height"`
}
// TallyParams contains the tally parameters of the x/gov module
type TallyParams struct {
Quorum sdk.Dec `json:"quorum,omitempty"`
Threshold sdk.Dec `json:"threshold,omitempty"`
VetoThreshold sdk.Dec `json:"veto_threshold,omitempty" yaml:"veto_threshold"`
}
// NewTallyParams allows to build a new TallyParams instance
func NewTallyParams(t govtypes.TallyParams) TallyParams {
return TallyParams{
Quorum: t.Quorum,
Threshold: t.Threshold,
VetoThreshold: t.VetoThreshold,
}
}
// NewGovParams allows to build a new GovParams instance
func NewGovParams(votingParams VotingParams, depositParams DepositParams, tallyParams TallyParams, height int64) *GovParams {
return &GovParams{
DepositParams: depositParams,
VotingParams: votingParams,
TallyParams: tallyParams,
Height: height,
}
}
// --------------------------------------------------------------------------------------------------------------------
// Proposal represents a single governance proposal
type Proposal struct {
ProposalRoute string
ProposalType string
ProposalID uint64
Content govtypes.Content
Status string
SubmitTime time.Time
DepositEndTime time.Time
VotingStartTime time.Time
VotingEndTime time.Time
Proposer string
}
// NewProposal return a new Proposal instance
func NewProposal(
proposalID uint64,
proposalRoute string,
proposalType string,
content govtypes.Content,
status string,
submitTime time.Time,
depositEndTime time.Time,
votingStartTime time.Time,
votingEndTime time.Time,
proposer string,
) Proposal {
return Proposal{
Content: content,
ProposalRoute: proposalRoute,
ProposalType: proposalType,
ProposalID: proposalID,
Status: status,
SubmitTime: submitTime,
DepositEndTime: depositEndTime,
VotingStartTime: votingStartTime,
VotingEndTime: votingEndTime,
Proposer: proposer,
}
}
// Equal tells whether p and other contain the same data
func (p Proposal) Equal(other Proposal) bool {
return p.ProposalRoute == other.ProposalRoute &&
p.ProposalType == other.ProposalType &&
p.ProposalID == other.ProposalID &&
p.Content.String() == other.Content.String() &&
p.Status == other.Status &&
p.SubmitTime.Equal(other.SubmitTime) &&
p.DepositEndTime.Equal(other.DepositEndTime) &&
p.VotingStartTime.Equal(other.VotingStartTime) &&
p.VotingEndTime.Equal(other.VotingEndTime) &&
p.Proposer == other.Proposer
}
// ProposalUpdate contains the data that should be used when updating a governance proposal
type ProposalUpdate struct {
ProposalID uint64
Status string
VotingStartTime time.Time
VotingEndTime time.Time
}
// NewProposalUpdate allows to build a new ProposalUpdate instance
func NewProposalUpdate(
proposalID uint64, status string, votingStartTime, votingEndTime time.Time,
) ProposalUpdate {
return ProposalUpdate{
ProposalID: proposalID,
Status: status,
VotingStartTime: votingStartTime,
VotingEndTime: votingEndTime,
}
}
// -------------------------------------------------------------------------------------------------------------------
// Deposit contains the data of a single deposit made towards a proposal
type Deposit struct {
ProposalID uint64
Depositor string
Amount sdk.Coins
Height int64
}
// NewDeposit return a new Deposit instance
func NewDeposit(
proposalID uint64,
depositor string,
amount sdk.Coins,
height int64,
) Deposit {
return Deposit{
ProposalID: proposalID,
Depositor: depositor,
Amount: amount,
Height: height,
}
}
// -------------------------------------------------------------------------------------------------------------------
// Vote contains the data of a single proposal vote
type Vote struct {
ProposalID uint64
Voter string
Option govtypes.VoteOption
Height int64
}
// NewVote return a new Vote instance
func NewVote(
proposalID uint64,
voter string,
option govtypes.VoteOption,
height int64,
) Vote {
return Vote{
ProposalID: proposalID,
Voter: voter,
Option: option,
Height: height,
}
}
// -------------------------------------------------------------------------------------------------------------------
// TallyResult contains the data about the final results of a proposal
type TallyResult struct {
ProposalID uint64
Yes string
Abstain string
No string
NoWithVeto string
Height int64
}
// NewTallyResult return a new TallyResult instance
func NewTallyResult(
proposalID uint64,
yes string,
abstain string,
no string,
noWithVeto string,
height int64,
) TallyResult {
return TallyResult{
ProposalID: proposalID,
Yes: yes,
Abstain: abstain,
No: no,
NoWithVeto: noWithVeto,
Height: height,
}
}
// -------------------------------------------------------------------------------------------------------------------
// ProposalStakingPoolSnapshot contains the data about a single staking pool snapshot to be associated with a proposal
type ProposalStakingPoolSnapshot struct {
ProposalID uint64
Pool *Pool
}
// NewProposalStakingPoolSnapshot returns a new ProposalStakingPoolSnapshot instance
func NewProposalStakingPoolSnapshot(proposalID uint64, pool *Pool) ProposalStakingPoolSnapshot {
return ProposalStakingPoolSnapshot{
ProposalID: proposalID,
Pool: pool,
}
}
// -------------------------------------------------------------------------------------------------------------------
// ProposalValidatorStatusSnapshot represents a single snapshot of the status of a validator associated
// with a single proposal
type ProposalValidatorStatusSnapshot struct {
ProposalID uint64
ValidatorConsAddress string
ValidatorVotingPower int64
ValidatorStatus int
ValidatorJailed bool
Height int64
}
// NewProposalValidatorStatusSnapshot returns a new ProposalValidatorStatusSnapshot instance
func NewProposalValidatorStatusSnapshot(
proposalID uint64,
validatorConsAddr string,
validatorVotingPower int64,
validatorStatus int,
validatorJailed bool,
height int64,
) ProposalValidatorStatusSnapshot {
return ProposalValidatorStatusSnapshot{
ProposalID: proposalID,
ValidatorStatus: validatorStatus,
ValidatorConsAddress: validatorConsAddr,
ValidatorVotingPower: validatorVotingPower,
ValidatorJailed: validatorJailed,
Height: height,
}
}