-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvalidator.go
155 lines (125 loc) · 5.49 KB
/
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
package models
import (
"database/sql/driver"
"fmt"
"github.com/forbole/juno/v4/common"
)
const PubkeyLength = 64
type Pubkey [PubkeyLength]byte
// SetBytes sets the pubkey to the value of b.
// If b is larger than len(k), b will be cropped from the left.
func (k *Pubkey) SetBytes(b []byte) {
if len(b) > len(k) {
b = b[len(b)-PubkeyLength:]
}
copy(k[PubkeyLength-len(b):], b)
}
func BytesToPubkey(b []byte) Pubkey {
var k Pubkey
(&k).SetBytes(b)
return k
}
// Scan implements Scanner for database/sql.
func (k *Pubkey) Scan(src interface{}) error {
srcB, ok := src.([]byte)
if !ok {
return fmt.Errorf("can't scan %T into Pubkey", src)
}
if len(srcB) != PubkeyLength {
return fmt.Errorf("can't scan []byte of len %d into Pubkey, want %d", len(srcB), PubkeyLength)
}
copy(k[:], srcB)
return nil
}
// Value implements valuer for database/sql.
func (k Pubkey) Value() (driver.Value, error) {
return k[:], nil
}
type Validator struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ConsensusAddress common.Address `gorm:"column:consensus_address;type:binary(20);not null;uniqueIndex:idx_address"`
ConsensusPubkey Pubkey `gorm:"column:consensus_pubkey;type:binary(64);not null;uniqueIndex:idx_pubkey"`
}
func (*Validator) TableName() string {
return "validators"
}
// ValidatorInfo is managed by upgrade module
type ValidatorInfo struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
OperatorAddress common.Address `gorm:"column:operator_address"`
SelfDelegateAddress common.Address `gorm:"column:self_delegate_address"` // refer account(addr)
MaxChangeRate string `gorm:"column:max_change_rate"`
MaxRate string `gorm:"column:max_rate"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorInfo) TableName() string {
return "validator_infos"
}
// ValidatorDescription is managed by upgrade module
type ValidatorDescription struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
Moniker string `gorm:"column:moniker"`
Identity string `gorm:"column:identity"`
AvatarUrl string `gorm:"column:avatar_url"`
Website string `gorm:"column:website"`
SecurityContact string `gorm:"column:security_contact"`
Details string `gorm:"column:details"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorDescription) TableName() string {
return "validator_descriptions"
}
// ValidatorCommission is managed by upgrade module
type ValidatorCommission struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
Commission uint64 `gorm:"column:commission"`
MinSelfDelegation uint64 `gorm:"column:min_self_delegation"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorCommission) TableName() string {
return "validator_commissions"
}
// ValidatorVotingPower is managed by staking module
type ValidatorVotingPower struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
VotingPower uint64 `gorm:"column:voting_power"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorVotingPower) TableName() string {
return "validator_voting_powers"
}
// ValidatorStatus is managed by staking and gov module
type ValidatorStatus struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
Status int `gorm:"column:status"`
Jailed bool `gorm:"column:jailed"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorStatus) TableName() string {
return "validator_statuses"
}
// ValidatorSigningInfo is managed by slashing module
type ValidatorSigningInfo struct {
ID uint64 `gorm:"column:id;primaryKey" json:"-"`
ValidatorAddress common.Address `gorm:"column:validator_address;type:binary(20);not null;uniqueIndex:idx_address"` // refer validator(consensus_address)
StartHeight uint64 `gorm:"column:start_height"` // not null
IndexOffset uint64 `gorm:"column:index_offset"` // not null
JailedUntil uint64 `gorm:"column:jailed_until"`
Tombstoned bool `gorm:"column:tombstoned"`
MissedBlocksCounter uint64 `gorm:"column:missed_blocks_counter"`
Height uint64 `gorm:"column:height;index:idx_height"`
}
func (*ValidatorSigningInfo) TableName() string {
return "validator_signing_infos"
}
func NewValidator(ConsensusAddress common.Address, ConsensusPubkey Pubkey) *Validator {
return &Validator{
ConsensusAddress: ConsensusAddress,
ConsensusPubkey: ConsensusPubkey,
}
}