|
|
@ -90,14 +90,17 @@ func (valSet *ValidatorSet) HasAddress(address []byte) bool { |
|
|
|
return idx != len(valSet.Validators) && bytes.Equal(valSet.Validators[idx].Address, address) |
|
|
|
} |
|
|
|
|
|
|
|
// GetByAddress returns an index of the validator with address and validator
|
|
|
|
// itself if found. Otherwise, -1 and nil are returned.
|
|
|
|
func (valSet *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator) { |
|
|
|
idx := sort.Search(len(valSet.Validators), func(i int) bool { |
|
|
|
return bytes.Compare(address, valSet.Validators[i].Address) <= 0 |
|
|
|
}) |
|
|
|
if idx != len(valSet.Validators) && bytes.Equal(valSet.Validators[idx].Address, address) { |
|
|
|
return idx, valSet.Validators[idx].Copy() |
|
|
|
} else { |
|
|
|
return -1, nil |
|
|
|
} |
|
|
|
return 0, nil |
|
|
|
} |
|
|
|
|
|
|
|
// GetByIndex returns the validator by index.
|
|
|
|