getTransactions function
GET request to the /transactions-histroy endpoint. Returns a list of forged transaction based on certain filters @param {string} address - Filter by the address that sent or received the transactions. 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} batchNum - Filter by batch number @param {String} accountIndex - Filter by an account index that sent or received the transactions @param {int} fromItem - Item from where to start the request @returns {object} Response data with filtered transactions and pagination data
Implementation
Future<ForgedTransactionsResponse> getTransactions(
{String? address,
List<int>? tokenIds,
int? batchNum,
String? accountIndex,
int fromItem = 0,
PaginationOrder order = PaginationOrder.ASC,
int limit = DEFAULT_PAGE_SIZE}) async {
Map<String, String> params = {};
if (address != null && address.isNotEmpty && isHermezEthereumAddress(address))
params.putIfAbsent('hezEthereumAddress', () => address);
if (address != null && address.isNotEmpty && isHermezBjjAddress(address))
params.putIfAbsent('BJJ', () => address);
if (tokenIds != null && tokenIds.isNotEmpty)
params.putIfAbsent('tokenIds', () => tokenIds.join(','));
if (batchNum != null && batchNum > 0) {
params.putIfAbsent('batchNum', () => batchNum.toString());
}
if (accountIndex != null && accountIndex.isNotEmpty) {
params.putIfAbsent('accountIndex', () => accountIndex);
}
params.addAll(getPageData(fromItem, order, limit));
final response =
await get(baseApiUrl, TRANSACTIONS_HISTORY_URL, queryParameters: params);
if (response.statusCode == 200) {
final jsonResponse = await extractJSON(response);
final ForgedTransactionsResponse forgedTransactionsResponse =
ForgedTransactionsResponse.fromJson(json.decode(jsonResponse));
return forgedTransactionsResponse;
} else {
throw ('Error: ${response.body}');
}
}