getTransactions method

Future<Set<TronTransaction>> getTransactions({
  1. required String address,
  2. required CoinEntity token,
  3. int limit = 10,
  4. int? startTimestamp,
  5. int? endTimestamp,
  6. String? type,
  7. String? method,
  8. List<String>? tokens,
})

Implementation

Future<Set<TronTransaction>> getTransactions({
  required String address,
  required CoinEntity token,
  int limit = 10,
  int? startTimestamp,
  int? endTimestamp,
  String? type,
  String? method,
  List<String>? tokens,
}) async {
  assert(limit <= 50, "Limit must be less than or equal to 50");

  final data = [];

  int? totalLength;
  for (int i = 0; true; i += limit) {
    final endpoint = getTransactionsEndpont(
      start: i,
      address: address,
      limit: limit,
      startTimestamp: startTimestamp,
      endTimestamp: endTimestamp,
      type: type,
      method: method,
      tokens: tokens,
    );

    final result = await getCall<JSON>(endpoint);

    totalLength ??= result['total'] as int;

    final newData = result['data'];

    data.addAll(newData);

    if (data.length >= totalLength) {
      break;
    }
  }

  return {
    for (final item in data) TronTransaction.fromJson(item, token, address),
  }.whereType<TronTransaction>().toSet();
}