getTransactions method

Future<List<RosettaTransaction>> getTransactions(
  1. int limit,
  2. int maxBlockIndex,
  3. int offset
)

Return an array of Transaction objects based on the specified parameters, or an empty array if none found. @param limit {number} The maximum number of transactions to return in one call. @param maxBlockIndex {number} The block index to start at. If not specified, start at current block. @param offset {number} The offset from maxBlockIndex to start returning transactions. @returns {Promise<Array

Implementation

Future<List<RosettaTransaction>> getTransactions(
    int limit, int maxBlockIndex, int offset) async {
  try {
    // This function can be simplified once /search/transactions supports using the properties
    // max_block, offset, and limit.
    int blockIndex;
    if (maxBlockIndex > 0) {
      blockIndex = maxBlockIndex;
    } else {
      // Get the latest block index.
      final response = await networkStatus();
      blockIndex = response.current_block_identifier.index;
    }
    if (offset > 0) {
      blockIndex = max(blockIndex - offset, -1);
    }

    final transactionCount = min(limit, blockIndex + 1);
    final transactions = <RosettaTransaction>[];
    for (var i = 0; i < transactionCount; i++) {
      transactions.add(await getTransactionByBlock(blockIndex - i));
    }
    return transactions;
  } catch (error) {
    //console.log(error);
    rethrow;
  }
}