import IBlockchain from './interfaces/IBlockchain'; import IOperationStore from './interfaces/IOperationStore'; import ITransactionStore from './interfaces/ITransactionStore'; import IUnresolvableTransactionStore from './interfaces/IUnresolvableTransactionStore'; import IVersionManager from './interfaces/IVersionManager'; /** * Class that performs periodic processing of batches of Sidetree operations anchored to the blockchain. */ export default class Observer { private versionManager; private blockchain; private maxConcurrentDownloads; private operationStore; private transactionStore; private unresolvableTransactionStore; private observingIntervalInSeconds; /** * Denotes if the periodic transaction processing should continue to occur. * Used mainly for test purposes. */ private continuePeriodicProcessing; /** * The list of transactions that are being downloaded or processed. */ private transactionsUnderProcessing; /** * This is the transaction that is used as a timestamp to fetch newer transaction. */ private lastKnownTransaction; constructor(versionManager: IVersionManager, blockchain: IBlockchain, maxConcurrentDownloads: number, operationStore: IOperationStore, transactionStore: ITransactionStore, unresolvableTransactionStore: IUnresolvableTransactionStore, observingIntervalInSeconds: number); /** * The method that starts the periodic polling and processing of Sidetree operations. */ startPeriodicProcessing(): Promise; /** * Stops periodic transaction processing. * Mainly used for test purposes. */ stopPeriodicProcessing(): void; /** * Processes new transactions if any, then reprocess a set of unresolvable transactions if any, * then scehdules the next round of processing unless `stopPeriodicProcessing()` is invoked. */ processTransactions(): Promise; private waitUntilCountOfTransactionsUnderProcessingIsLessOrEqualTo; /** * Attempts to fetch and process unresolvable transactions due for retry. * Waits until all unresolvable transactions due for retry are processed. */ private processUnresolvableTransactions; /** * Goes through the `transactionsUnderProcessing` in chronological order, records each processed transaction * in the transaction store and remove it from `transactionsUnderProcessing` until a transaction that has not been processed yet is hit. */ private storeConsecutiveTransactionsProcessed; /** * Processes the given transaction by passing the transaction to the right version of the transaction processor based on the transaction time. * The transaction processing generically involves first downloading DID operation data from CAS (Content Addressable Storage), * then storing the operations indexed/grouped by DIDs in the persistent operation DB. */ private processTransaction; /** * Reverts invalid transactions. Used in the event of a block-reorganization. */ private revertInvalidTransactions; }