-
Notifications
You must be signed in to change notification settings - Fork 199
/
validator.go
59 lines (47 loc) · 1.2 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
package nodesCoordinator
import (
"encoding/hex"
"fmt"
)
const intSize = 8
var _ Validator = (*validator)(nil)
type validator struct {
pubKey []byte
chances uint32
index uint32
}
// NewValidator creates a new instance of a validator
func NewValidator(pubKey []byte, chances uint32, index uint32) (*validator, error) {
if pubKey == nil {
return nil, ErrNilPubKey
}
return &validator{
pubKey: pubKey,
chances: chances,
index: index,
}, nil
}
// PubKey returns the validator's public key
func (v *validator) PubKey() []byte {
return v.pubKey
}
// Chances returns the validator's chances
func (v *validator) Chances() uint32 {
return v.chances
}
// Index returns the validators index
func (v *validator) Index() uint32 {
return v.index
}
// String returns the toString representation of the validator
func (v *validator) String() string {
return fmt.Sprintf("%s %v %v", hex.EncodeToString(v.pubKey), v.index, v.chances)
}
// Size returns the size in bytes held by an instance of this struct
func (v *validator) Size() int {
return len(v.pubKey) + intSize
}
// IsInterfaceNil returns true if there is no value under the interface
func (v *validator) IsInterfaceNil() bool {
return v == nil
}