getExits function

Future<ExitsResponse> getExits(
  1. String? address,
  2. bool onlyPendingWithdraws,
  3. int tokenId
)

GET request to the /exits endpoint. Returns a list of exits based on certain filters @param {string} address - Filter by the address associated to the exits. It can be a Hermez Ethereum address or a Hermez BabyJubJub address @param {boolean} onlyPendingWithdraws - Filter by exits that still haven't been withdrawn @returns {object} Response data with the list of exits

Implementation

Future<ExitsResponse> getExits(
    String? address, bool onlyPendingWithdraws, int tokenId) async {
  Map<String, String?> params = {};
  if (isHermezEthereumAddress(address) && address!.isNotEmpty)
    params.putIfAbsent('hezEthereumAddress', () => address);
  if (isHermezBjjAddress(address) && address!.isNotEmpty)
    params.putIfAbsent('BJJ', () => address);
  params.putIfAbsent(
      'onlyPendingWithdraws', () => onlyPendingWithdraws.toString());
  if (tokenId >= 0) {
    params.putIfAbsent('tokenId', () => tokenId.toString());
  }
  final response = await get(baseApiUrl, EXITS_URL, queryParameters: params);
  if (response.statusCode == 200) {
    final jsonResponse = await extractJSON(response);
    final ExitsResponse exitsResponse =
        ExitsResponse.fromJson(json.decode(jsonResponse));
    return exitsResponse;
  } else {
    throw ('Error: $response.statusCode');
  }
}