-
Notifications
You must be signed in to change notification settings - Fork 198
/
indexHashedNodesCoordinatorWithRater.go
51 lines (41 loc) · 1.3 KB
/
indexHashedNodesCoordinatorWithRater.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
package sharding
import (
"github.com/ElrondNetwork/elrond-go/core/check"
)
type indexHashedNodesCoordinatorWithRater struct {
*indexHashedNodesCoordinator
RatingReader
}
// NewIndexHashedNodesCoordinator creates a new index hashed group selector
func NewIndexHashedNodesCoordinatorWithRater(
indexNodesCoordinator *indexHashedNodesCoordinator,
rater RatingReader,
) (*indexHashedNodesCoordinatorWithRater, error) {
if check.IfNil(indexNodesCoordinator) {
return nil, ErrNilNodesCoordinator
}
if check.IfNil(rater) {
return nil, ErrNilRater
}
ihncr := &indexHashedNodesCoordinatorWithRater{
indexHashedNodesCoordinator: indexNodesCoordinator,
RatingReader: rater,
}
indexNodesCoordinator.doExpandEligibleList = ihncr.expandEligibleList
return ihncr, nil
}
func (ihgs *indexHashedNodesCoordinatorWithRater) expandEligibleList(shardId uint32) []Validator {
validatorList := make([]Validator, 0)
for _, validator := range ihgs.nodesMap[shardId] {
pk := validator.PubKey()
rating := ihgs.GetRating(string(pk))
for i := uint32(0); i < rating; i++ {
validatorList = append(validatorList, validator)
}
}
return validatorList
}
//IsInterfaceNil verifies that the underlying value is nil
func (ihgs *indexHashedNodesCoordinatorWithRater) IsInterfaceNil() bool {
return ihgs == nil
}