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<Transaction>|null>} An array of Transaction objects, or a TransactionError for error.

Implementation

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

  final transactionCount = min(limit, blockIndex + 1);
  final transactions = <RosettaTransaction>[];
  for (int i = 0; i < transactionCount; i++) {
    transactions.add(await getTransactionByBlock(blockIndex - i));
  }
  return transactions;
}