-
Notifications
You must be signed in to change notification settings - Fork 0
/
staking.go
191 lines (168 loc) · 5.78 KB
/
staking.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
package types
// DoubleSignEvidence represent a double sign evidence on each tendermint block
type DoubleSignEvidence struct {
VoteA DoubleSignVote
VoteB DoubleSignVote
Height int64
}
// NewDoubleSignEvidence return a new DoubleSignEvidence object
func NewDoubleSignEvidence(height int64, voteA DoubleSignVote, voteB DoubleSignVote) DoubleSignEvidence {
return DoubleSignEvidence{
VoteA: voteA,
VoteB: voteB,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// DoubleSignVote represents a double vote which is included inside a DoubleSignEvidence
type DoubleSignVote struct {
BlockID string
ValidatorAddress string
Signature string
Type int
Height int64
Round int32
ValidatorIndex int32
}
// NewDoubleSignVote allows to create a new DoubleSignVote instance
func NewDoubleSignVote(
roundType int,
height int64,
round int32,
blockID string,
validatorAddress string,
validatorIndex int32,
signature string,
) DoubleSignVote {
return DoubleSignVote{
Type: roundType,
Height: height,
Round: round,
BlockID: blockID,
ValidatorAddress: validatorAddress,
ValidatorIndex: validatorIndex,
Signature: signature,
}
}
// ----------------------------------------------------------------------------------------------------------
// Validator contains the data of a single validator
type Validator struct {
ConsensusAddr string
SelfDelegateAddress string
Height int64
}
// NewValidator allows to build a new Validator instance
func NewValidator(
consAddr string,
selfDelegateAddress string,
height int64,
) Validator {
return Validator{
ConsensusAddr: consAddr,
SelfDelegateAddress: selfDelegateAddress,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorCommission contains the data of a validator commission at a given height
type ValidatorCommission struct {
ValAddress string
SelfDelegateAddress string
Commission string
MinSelfDelegation string
Height int64
}
// NewValidatorCommission return a new ValidatorCommission instance
func NewValidatorCommission(
valAddress, selfDelegateAddress, commission, minSelfDelegation string, height int64,
) ValidatorCommission {
return ValidatorCommission{
ValAddress: valAddress,
SelfDelegateAddress: selfDelegateAddress,
Commission: commission,
MinSelfDelegation: minSelfDelegation,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorDescription contains the description of a validator
// and timestamp do the description get changed
type ValidatorDescription struct {
OperatorAddress string
SelfDelegateAddress string
Description string
Identity string
Moniker string
Height int64
}
// NewValidatorDescription returns a new ValidatorDescription object
func NewValidatorDescription(
opAddr, selfDelegateAddress, description, identity string, moniker string, height int64,
) ValidatorDescription {
return ValidatorDescription{
OperatorAddress: opAddr,
SelfDelegateAddress: selfDelegateAddress,
Description: description,
Identity: identity,
Moniker: moniker,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorsList represents validators list from a file
type ValidatorsList struct {
Validators []ValidatorList `yaml:"validators"`
}
type ValidatorList struct {
Validator ValidatorInfo `yaml:"validator"`
}
type ValidatorInfo struct {
Address string `yaml:"address"`
Commission string `yaml:"commission"`
Details string `yaml:"details"`
Identity string `yaml:"identity"`
Jailed string `yaml:"jailed"`
MinSelfDelegation string `yaml:"min_self_delegation"`
Moniker string `yaml:"moniker"`
Tombstoned string `yaml:"tombstoned"`
InActiveSet string `yaml:"in_active_set"`
VotingPower string `yaml:"voting_power"`
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorVotingPower represents the voting power of a validator at a specific block height
type ValidatorVotingPower struct {
ConsensusAddress string
SelfDelegateAddress string
VotingPower string
Height int64
}
// NewValidatorVotingPower creates a new ValidatorVotingPower
func NewValidatorVotingPower(address, selfDelegateAddress string, votingPower string, height int64) ValidatorVotingPower {
return ValidatorVotingPower{
ConsensusAddress: address,
VotingPower: votingPower,
SelfDelegateAddress: selfDelegateAddress,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorStatus represents the latest state of a validator
type ValidatorStatus struct {
ConsensusAddress string
SelfDelegateAddress string
InActiveSet string
Jailed string
Tombstoned string
Height int64
}
// NewValidatorStatus creates a new ValidatorVotingPower
func NewValidatorStatus(valConsAddr, selfDelegateAddress, inActiveSet, jailed, tombstoned string, height int64) ValidatorStatus {
return ValidatorStatus{
ConsensusAddress: valConsAddr,
SelfDelegateAddress: selfDelegateAddress,
InActiveSet: inActiveSet,
Jailed: jailed,
Tombstoned: tombstoned,
Height: height,
}
}