getActiveValidators method

Future<List<ValidatorInfo>> getActiveValidators({
  1. int? epochId,
  2. int pageSize = 50,
  3. String? after,
})

All active validators, paging from after with requests of pageSize.

Implementation

Future<List<ValidatorInfo>> getActiveValidators({
  int? epochId,
  int pageSize = 50,
  String? after,
}) async {
  _checkPageSize(pageSize, 'pageSize');
  final validators = <ValidatorInfo>[];
  var cursor = after;
  final seenCursors = <String?>{cursor};

  while (true) {
    final page = await getActiveValidatorsPage(
      epochId: epochId,
      first: pageSize,
      after: cursor,
    );
    validators.addAll(page.validators);
    if (!page.hasNextPage) break;
    final nextCursor = page.endCursor;
    if (nextCursor == null || !seenCursors.add(nextCursor)) {
      throw StateError('Invalid validator pagination cursor');
    }
    cursor = nextCursor;
  }
  return validators;
}