Fix getAllValidatorInformation.

pull/4134/head
Konstantin 3 years ago committed by Leo Chen
parent 23d38db744
commit 3c8286279d
  1. 17
      rpc/staking.go

@ -338,25 +338,22 @@ func (s *PublicStakingService) getPagedValidatorInformationCached(ctx context.Co
func (s *PublicStakingService) getAllValidatorInformation(
ctx context.Context, page int, blockNum uint64,
) (interface{}, error) {
if page < -1 {
return nil, errors.Errorf("page given %d cannot be less than -1", page)
if page < 0 {
return nil, errors.Errorf("page given %d cannot be less than 0", page)
}
// Get all validators
addresses := s.hmy.GetAllValidatorAddresses()
if page != -1 && len(addresses) <= page*validatorsPageSize {
if len(addresses) <= page*validatorsPageSize {
return []StructuredResponse{}, nil
}
// Set page start
validatorsNum := len(addresses)
start := 0
if page != -1 {
validatorsNum = validatorsPageSize
start = page * validatorsPageSize
if len(addresses)-start < validatorsPageSize {
validatorsNum = len(addresses) - start
}
validatorsNum := validatorsPageSize
start = page * validatorsPageSize
if len(addresses)-start < validatorsPageSize {
validatorsNum = len(addresses) - start
}
// Fetch block

Loading…
Cancel
Save