Class ChainWalker

The ChainWalker allows to either walk from a given block height until the last mined block and/or to listen to the blockchain.

Usage Listen Mode

When you just need to react on incoming blocks/transactions

Usage Walk Mode

When you want to gather data from the ledger, i.e. reading past blocks/transactions. Good for analysis, or (re)building a database.

In each mode the same callbacks are called, such that blocks and transactions can be processed according your needs.

The callbacks are called in this order:

  1. onPendingTransactions
  2. onTransaction
  3. onBlock

and when stopping/interrupting onBeforeQuit

Hierarchy

  • ChainWalker

Constructors

Properties

beforeQuitHandler: BeforeQuitHandler = ...
blockHandler: BlockHandler
cache: Cache
config: ChainWalkerConfig = DefaultConfig
ledger: MockLedger | Api
logger: BaseLogger
pendingTransactionsHandler: PendingTransactionsHandler
scheduler: null | ToadScheduler = null
stopRequested: boolean = false
transactionHandler: TransactionHandler

Accessors

  • get ledgerClient(): Api
  • Returns Api

    the internal ledger client

Methods

  • Parameters

    • height: number

    Returns Promise<null | Block>

  • Returns Promise<number>

  • Listens for blocks starting at last mined block. Consider running walk before, if you need to process the history also.

    Note

    The config parameter intervalSeconds

    Returns Promise<void>

  • Sets the transaction handler for pending transactions.

    Pending transactions handler gives you all pending transactions on all periodical calls. You need to track on your behalf if these transactions were processed by you or not. This method ignores blockOffset.

    Parameters

    Returns ChainWalker

  • Returns Promise<{
        processedBlock: number;
        processingError: string;
    }>

  • Iterates over the blocks beginning with startHeight until the current block. This method processes each block as quick as possible (depending on the handlers), without any further delays. Usually, you want to use this before listen

    Usage

    This method is useful, if you want to reconstruct for example a database based on the blockchain data. Due to its immutability and integrity the blockchain is your "Single Source of Truth" and though your secure backup.

    Note, that this operation can take several minutes. It can be sped up significantly, if running against a local node.

    Note

    On processing errors this method tries to recover, i.e. retrying several times (p-retry) before it stops.

    Parameters

    • Optional startHeight: number

      The block height where to start. If there's a cached height > startHeight, the cached height is taken instead. This way it is possible, to continue on already processed data and somehow halted process (due to processing errors), without beginning from the startHeight. If you really want to start from scratch you need to delete the cache file.

    Returns Promise<void>

Generated using TypeDoc