Options
All
  • Public
  • Public/Protected
  • All
Menu

Reads blocks from a blockchain, outputting normalized Block objects.

Hierarchy

  • AbstractActionReader

Index

Constructors

constructor

Properties

Protected blockHistory

blockHistory: Block[] = []

Protected currentBlockData

currentBlockData: Block = defaultBlock

currentBlockNumber

currentBlockNumber: number

headBlockNumber

headBlockNumber: number = 0

Protected initialized

initialized: boolean = false

Protected lastIrreversibleBlockNumber

lastIrreversibleBlockNumber: number = 0

Protected log

log: Logger

Protected onlyIrreversible

onlyIrreversible: boolean

startAtBlock

startAtBlock: number

Accessors

info

info:

Information about the current state of the Action Reader

Methods

Private acceptBlock

  • acceptBlock(blockData: Block): void

Private addPreviousBlockToHistory

  • addPreviousBlockToHistory(checkIrreversiblility?: boolean): Promise<void>

Abstract getBlock

  • getBlock(blockNumber: number): Promise<Block>
  • Loads a block with the given block number, returning a promise for a Block.

    Parameters

    • blockNumber: number

      The number of the block to load

    Returns Promise<Block>

Abstract getHeadBlockNumber

  • getHeadBlockNumber(): Promise<number>

Abstract getLastIrreversibleBlockNumber

  • getLastIrreversibleBlockNumber(): Promise<number>

Private getLatestNeededBlockNumber

  • getLatestNeededBlockNumber(): Promise<number>

getNextBlock

  • Loads, processes, and returns the next block, updating all relevant state. Return value at index 0 is the Block instance; return value at index 1 boolean isRollback determines if the implemented AbstractActionHandler needs to potentially reverse processed blocks (in the event of a fork); return value at index 2 boolean isNewBlock indicates if the Block instance returned is the same one that was just returned from the last call of nextBlock.

    Returns Promise<NextBlock>

Private initBlockState

  • initBlockState(): Promise<void>

initialize

  • initialize(): Promise<void>

Private logForkDetected

  • logForkDetected(unvalidatedBlockData: Block, expectedHash: string, actualHash: string): void

Private logForkMismatch

Private logForkResolved

Private pruneHistory

  • pruneHistory(): void

Private range

  • range(start: number, end: number): number[]

Private reloadHistory

  • reloadHistory(maxTries?: number): Promise<void>

Protected resolveFork

  • resolveFork(): Promise<void>
  • Incrementally rolls back reader state one block at a time, comparing the blockHistory with newly fetched blocks. Fork resolution is finished when either the current block's previous hash matches the previous block's hash, or when history is exhausted.

    Returns Promise<void>

seekToBlock

  • seekToBlock(blockNumber: number): Promise<void>
  • Changes the state of the AbstractActionReader instance to have just processed the block at the given block number. If the block exists in its temporary block history, it will use this, otherwise it will fetch the block using getBlock.

    The next time nextBlock() is called, it will load the block after this input block number.

    Parameters

    • blockNumber: number

    Returns Promise<void>

Protected Abstract setup

  • setup(): Promise<void>