-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_vault.go
39 lines (30 loc) · 1.1 KB
/
key_vault.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
package types
import (
fmt "fmt"
"github.com/furynet/xfury/utils"
)
// GetLeader sets the current leader of public keys.
func (k *KeyVault) SetLeader(leaderIndex uint32) {
keys, leaderKey := utils.PopStrAtIndex(k.PublicKeys, leaderIndex)
// set the leader as first item in the list
k.PublicKeys = append([]string{leaderKey}, keys...)
}
// GetLeader returns the current leader of public keys.
func (k *KeyVault) GetLeader() string {
return k.PublicKeys[0]
}
// validatePubKeys validates the public keys stored in the key vault.
func (k *KeyVault) validatePubKeys() error {
count := len(k.PublicKeys)
if count < minPubKeysCount {
return fmt.Errorf("total number of pubkeys is %d, this should not be less than %d", count, minPubKeysCount)
}
if count > maxPubKeysCount {
return fmt.Errorf("total number of pubkeys is %d, this should not be more than %d", count, minPubKeysCount)
}
// if there are even number of public keys, there is a chance that proposal votes count get equal
if count%2 == 0 {
return fmt.Errorf("public keys count should be an odd number, its count is %d", count)
}
return nil
}