How to use the @requestnetwork/utils.unique function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / data-access / src / data-access.ts View on Github external
private getTransactionAndMetaFromPosition(
    transactionPositions: number[],
    block: DataAccessTypes.IBlock,
    location: string,
    meta: StorageTypes.IMetaOneData,
  ): {
    transactions: DataAccessTypes.IConfirmedTransaction[];
    transactionsStorageLocation: string[];
    storageMeta: string[];
  } {
    // Gets the transaction from the positions
    const transactions: DataAccessTypes.IConfirmedTransaction[] =
      // first remove de duplicates
      Utils.unique(transactionPositions).uniqueItems.map(
        // Get the transaction from their position and add the timestamp
        (position: number) => ({
          timestamp: meta.timestamp,
          transaction: block.transactions[position],
        }),
      );

    // Gets the list of storage location of the transactions found
    const transactionsStorageLocation = Array(transactions.length).fill(location);

    // Gets the list of storage meta of the transactions found
    const storageMeta = Array(transactions.length).fill(meta);

    return { transactions, transactionsStorageLocation, storageMeta };
  }