/
validator.go
49 lines (41 loc) · 1.03 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
package node
import (
"crypto/ecdsa"
"github.com/abassian/huron/src/crypto/keys"
)
//Validator struct holds information about the validator for a node
type Validator struct {
Key *ecdsa.PrivateKey
Moniker string
id uint32
pubBytes []byte
pubHex string
}
//NewValidator is a factory method for a Validator
func NewValidator(key *ecdsa.PrivateKey, moniker string) *Validator {
return &Validator{
Key: key,
Moniker: moniker,
}
}
//ID returns an ID for the validator
func (v *Validator) ID() uint32 {
if v.id == 0 {
v.id = keys.PublicKeyID(&v.Key.PublicKey)
}
return v.id
}
//PublicKeyBytes returns the validator's public key as a byte array
func (v *Validator) PublicKeyBytes() []byte {
if v.pubBytes == nil || len(v.pubBytes) == 0 {
v.pubBytes = keys.FromPublicKey(&v.Key.PublicKey)
}
return v.pubBytes
}
//PublicKeyHex returns the validator's public key as a hex string
func (v *Validator) PublicKeyHex() string {
if len(v.pubHex) == 0 {
v.pubHex = keys.PublicKeyHex(&v.Key.PublicKey)
}
return v.pubHex
}