getCoordinators function

Future<List<Coordinator>?> getCoordinators(
  1. String forgerAddr,
  2. String bidderAddr, {
  3. int fromItem = 0,
  4. PaginationOrder order = PaginationOrder.ASC,
  5. int limit = DEFAULT_PAGE_SIZE,
})

GET request to the /coordinators/:bidderAddr endpoint. Returns a specific coordinator information @param {String} forgerAddr - A coordinator forger address @param {String} bidderAddr - A coordinator bidder address @returns {Object} Response data with a specific coordinator

Implementation

Future<List<Coordinator>?> getCoordinators(String forgerAddr, String bidderAddr,
    {int fromItem = 0,
    PaginationOrder order = PaginationOrder.ASC,
    int limit = DEFAULT_PAGE_SIZE}) async {
  Map<String, String> params = {};
  params.putIfAbsent(
      'forgerAddr', () => forgerAddr.isNotEmpty ? forgerAddr : '');
  params.putIfAbsent(
      'bidderAddr', () => bidderAddr.isNotEmpty ? bidderAddr : '');
  params.addAll(getPageData(fromItem, order, limit));

  final response =
      await get(baseApiUrl, COORDINATORS_URL, queryParameters: params);
  if (response.statusCode == 200) {
    final jsonResponse = await extractJSON(response);
    final coordinatorsResponse =
        CoordinatorsResponse.fromJson(json.decode(jsonResponse));
    return coordinatorsResponse.coordinators;
  } else {
    throw ('Error: $response.statusCode');
  }
}