forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
staking_validator.go
166 lines (142 loc) · 4.64 KB
/
staking_validator.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
// Validator represents a single validator.
// This is defined as an interface so that we can use the SDK types
// as well as database types properly.
type Validator interface {
GetConsAddr() string
GetConsPubKey() string
GetOperator() string
GetSelfDelegateAddress() string
GetMaxChangeRate() *sdk.Dec
GetMaxRate() *sdk.Dec
GetHeight() int64
}
// validator allows to easily implement the Validator interface
type validator struct {
ConsensusAddr string
ConsPubKey string
OperatorAddr string
SelfDelegateAddress string
MaxChangeRate *sdk.Dec
MaxRate *sdk.Dec
Height int64
}
// NewValidator allows to build a new Validator implementation having the given data
func NewValidator(
consAddr string, opAddr string, consPubKey string,
selfDelegateAddress string, maxChangeRate *sdk.Dec,
maxRate *sdk.Dec, height int64,
) Validator {
return validator{
ConsensusAddr: consAddr,
ConsPubKey: consPubKey,
OperatorAddr: opAddr,
SelfDelegateAddress: selfDelegateAddress,
MaxChangeRate: maxChangeRate,
MaxRate: maxRate,
Height: height,
}
}
// GetConsAddr implements the Validator interface
func (v validator) GetConsAddr() string {
return v.ConsensusAddr
}
// GetConsPubKey implements the Validator interface
func (v validator) GetConsPubKey() string {
return v.ConsPubKey
}
func (v validator) GetOperator() string {
return v.OperatorAddr
}
func (v validator) GetSelfDelegateAddress() string {
return v.SelfDelegateAddress
}
func (v validator) GetMaxChangeRate() *sdk.Dec {
return v.MaxChangeRate
}
func (v validator) GetMaxRate() *sdk.Dec {
return v.MaxRate
}
func (v validator) GetHeight() int64 {
return v.Height
}
// --------------------------------------------------------------------------------------------------------------------
// ValidatorDescription contains the description of a validator
// and timestamp do the description get changed
type ValidatorDescription struct {
OperatorAddress string
Description stakingtypes.Description
AvatarURL string // URL of the avatar to be used. Will be [do-no-modify] if it shouldn't be edited
Height int64
}
// NewValidatorDescription return a new ValidatorDescription object
func NewValidatorDescription(
opAddr string, description stakingtypes.Description, avatarURL string, height int64,
) ValidatorDescription {
return ValidatorDescription{
OperatorAddress: opAddr,
Description: description,
AvatarURL: avatarURL,
Height: height,
}
}
// ----------------------------------------------------------------------------------------------------------
// ValidatorCommission contains the data of a validator commission at a given height
type ValidatorCommission struct {
ValAddress string
Commission *sdk.Dec
MinSelfDelegation *sdk.Int
Height int64
}
// NewValidatorCommission return a new validator commission instance
func NewValidatorCommission(
valAddress string, rate *sdk.Dec, minSelfDelegation *sdk.Int, height int64,
) ValidatorCommission {
return ValidatorCommission{
ValAddress: valAddress,
Commission: rate,
MinSelfDelegation: minSelfDelegation,
Height: height,
}
}
//--------------------------------------------
// ValidatorVotingPower represents the voting power of a validator at a specific block height
type ValidatorVotingPower struct {
ConsensusAddress string
VotingPower int64
Height int64
}
// NewValidatorVotingPower creates a new ValidatorVotingPower
func NewValidatorVotingPower(address string, votingPower int64, height int64) ValidatorVotingPower {
return ValidatorVotingPower{
ConsensusAddress: address,
VotingPower: votingPower,
Height: height,
}
}
//--------------------------------------------------------
// ValidatorStatus represents the current state for the specified validator at the specific height
type ValidatorStatus struct {
ConsensusAddress string
ConsensusPubKey string
Status int
Jailed bool
Tombstoned bool
Height int64
}
// NewValidatorStatus creates a new ValidatorVotingPower
func NewValidatorStatus(valConsAddr, pubKey string, status int, jailed bool, tombstoned bool, height int64) ValidatorStatus {
return ValidatorStatus{
ConsensusAddress: valConsAddr,
ConsensusPubKey: pubKey,
Status: status,
Jailed: jailed,
Tombstoned: tombstoned,
Height: height,
}
}
//---------------------------------------------------------------