Options
All
  • Public
  • Public/Protected
  • All
Menu

Takes blocks output from implementations of AbstractActionReader and processes their actions through the Updaters and Effects of the current HandlerVersion. Pass an object exposing a persistence API as state to the handleWithState method. Persist and retrieve information about the last block processed with updateIndexState and loadIndexState. Implement rollbackTo to handle when a fork is encountered.

Hierarchy

  • AbstractActionHandler

Index

Constructors

constructor

Properties

Private deferredEffects

deferredEffects: DeferredEffects

Private handlerVersionMap

handlerVersionMap: object

Type declaration

handlerVersionName

handlerVersionName: string = "v1"

Protected initialized

initialized: boolean = false

lastProcessedBlockHash

lastProcessedBlockHash: string = ""

lastProcessedBlockNumber

lastProcessedBlockNumber: number = 0

Protected log

log: Logger

Accessors

info

info:

Information about the current state of the Action Handler

Methods

Protected applyUpdaters

  • applyUpdaters(state: any, block: Block, context: any, isReplay: boolean): Promise<VersionedAction[]>
  • Process actions against deterministically accumulating Updater functions. Returns a promise of versioned actions for consumption by runEffects, to make sure the correct effects are run on blocks that include a HandlerVersion change. To change a HandlerVersion, have an Updater function return the versionName of the corresponding HandlerVersion you want to change to.

    Parameters

    • state: any
    • block: Block
    • context: any
    • isReplay: boolean

    Returns Promise<VersionedAction[]>

Private getNextDeferredBlockNumber

  • getNextDeferredBlockNumber(): number

Protected handleActions

  • handleActions(state: any, context: any, nextBlock: NextBlock, isReplay: boolean): Promise<void>

handleBlock

  • handleBlock(nextBlock: NextBlock, isReplay: boolean): Promise<number | null>

Private handleRollback

  • handleRollback(isRollback: boolean, blockNumber: number, isReplay: boolean, isEarliestBlock: boolean): Promise<void>
  • Parameters

    • isRollback: boolean
    • blockNumber: number
    • isReplay: boolean
    • isEarliestBlock: boolean

    Returns Promise<void>

Protected Abstract handleWithState

  • handleWithState(handle: function): Promise<void>
  • Must call the passed-in handle function within this method, passing in a state object that will be passed in to the state parameter to all calls of Updater.apply. Optionally, pass in a context object as a second parameter, which can be utilized to share state across Updater.apply and Effect.run calls on a per-block basis.

    Parameters

    • handle: function
        • (state: any, context?: any): void
        • Parameters

          • state: any
          • Optional context: any

          Returns void

    Returns Promise<void>

Private initHandlerVersions

initialize

  • initialize(): Promise<void>

Protected Abstract loadIndexState

  • Returns a promise for the lastProcessedBlockNumber and lastProcessedBlockHash meta state, coinciding with the block that has just been processed. These are the same values written by updateIndexState().

    Returns Promise<IndexState>

    A promise that resolves to an IndexState

Protected matchActionType

  • matchActionType(candidateType: string, subscribedType: string): boolean
  • This method is used when matching the types of incoming actions against the types the Updaters and Effects are subscribed to. When this returns true, their corresponding functions will run.

    By default, this method tests for direct equivalence between the incoming candidate type and the type that is subscribed. Override this method to extend this functionality (e.g. wildcards).

    Parameters

    • candidateType: string

      The incoming action's type

    • subscribedType: string

      The type the Updater of Effect is subscribed to

    Returns boolean

Private range

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

Private refreshIndexState

  • refreshIndexState(): Promise<void>

Private rollbackDeferredEffects

  • rollbackDeferredEffects(rollbackTo: number): void

Protected Abstract rollbackTo

  • rollbackTo(blockNumber: number): Promise<void>
  • Will run when a rollback block number is passed to handleActions. Implement this method to handle reversing actions full blocks at a time, until the last applied block is the block number passed to this method.

    Parameters

    • blockNumber: number

    Returns Promise<void>

Private runDeferredEffects

  • runDeferredEffects(lastIrreversibleBlockNumber: number): void

Protected runEffects

Private runOrDeferEffect

  • runOrDeferEffect(effect: Effect, payload: any, nextBlock: NextBlock, context: any): void

Protected Abstract setup

  • setup(): Promise<void>

Protected Abstract updateIndexState

  • updateIndexState(state: any, block: Block, isReplay: boolean, handlerVersionName: string, context?: any): Promise<void>
  • Updates the lastProcessedBlockNumber and lastProcessedBlockHash meta state, coinciding with the block that has just been processed. These are the same values read by updateIndexState().

    Parameters

    • state: any
    • block: Block
    • isReplay: boolean
    • handlerVersionName: string
    • Optional context: any

    Returns Promise<void>

Private warnHandlerVersionNonexistent

  • warnHandlerVersionNonexistent(newVersion: string): void

Private warnIncorrectFirstHandler

  • warnIncorrectFirstHandler(actualVersion: string): void

Private warnMissingHandlerVersion

  • warnMissingHandlerVersion(actualVersion: string): void

Private warnSkippingUpdaters

  • warnSkippingUpdaters(updaterIndex: number, actionType: string): void