getAccounts function

Future<AccountsResponse> getAccounts(
  1. String? address,
  2. List<int?> tokenIds, {
  3. int fromItem = 0,
  4. PaginationOrder order = PaginationOrder.ASC,
  5. int limit = DEFAULT_PAGE_SIZE,
})

GET request to the /accounts endpoint. Returns a list of token accounts associated to a Hermez address @param {string} address - The account's address. It can be a Hermez Ethereum address or a Hermez BabyJubJub address @param {int[]} tokenIds - Array of token IDs as registered in the network @param {int} fromItem - Item from where to start the request @returns {object} Response data with filtered token accounts and pagination data

Implementation

Future<AccountsResponse> getAccounts(String? address, List<int?> tokenIds,
    {int fromItem = 0,
    PaginationOrder order = PaginationOrder.ASC,
    int limit = DEFAULT_PAGE_SIZE}) async {
  Map<String, String?> params = {};
  if (isHermezEthereumAddress(address) && address!.isNotEmpty)
    params.putIfAbsent('hezEthereumAddress', () => address);
  else if (isHermezBjjAddress(address) && address!.isNotEmpty)
    params.putIfAbsent('BJJ', () => address);
  if (tokenIds.isNotEmpty)
    params.putIfAbsent('tokenIds', () => tokenIds.join(','));
  params.addAll(getPageData(fromItem, order, limit));
  final response = await get(baseApiUrl, ACCOUNTS_URL, queryParameters: params);
  if (response.statusCode == 200) {
    final jsonResponse = await extractJSON(response);
    final AccountsResponse accountsResponse =
        AccountsResponse.fromJson(json.decode(jsonResponse));
    return accountsResponse;
  } else {
    throw ('Error: $response.statusCode');
  }
}