Options
All
  • Public
  • Public/Protected
  • All
Menu

Connects to a Postgres database using MassiveJS. Make sure to call setupDatabase to create the needed internally-used tables _migration, _index_state, and _block_number_txid. This will also automatically migrate the database with the provided MigrationSequence if named init.

param

See HandlerVersion parameter from demux-js

param

An instance of of a massive object provided by MassiveJS, connected to the database you want this instance to interface with

param

The name of the schema you would like to use. If it doesn't exist, it will be created when setupDatabase is called.

param

An array of MigrationSequences available to call via state.migrate(<name of sequence>), commonly from Updater's apply functions that also change the HandlerVersion.

Hierarchy

  • AbstractActionHandler
    • MassiveActionHandler

Index

Constructors

constructor

Properties

Protected allMigrations

allMigrations: Migration[] = []

Protected dbSchema

dbSchema: string

handlerVersionName

handlerVersionName: string

Protected handlerVersions

handlerVersions: HandlerVersion[]

info

info: HandlerInfo

Information about the current state of the Action Handler

Protected initialized

initialized: boolean

lastProcessedBlockHash

lastProcessedBlockHash: string

lastProcessedBlockNumber

lastProcessedBlockNumber: number

Protected log

log: Logger

Protected massiveInstance

massiveInstance: any

Protected migrationSequenceByName

migrationSequenceByName: object

Type declaration

Protected migrationSequences

migrationSequences: MigrationSequence[]

Accessors

Protected schemaInstance

schemaInstance:

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[]>

Protected handleActions

  • handleActions(state: any, context: any, nextBlock: NextBlock, isReplay: boolean): Promise<void>
  • Calls applyUpdaters and runEffects on the given actions

    Parameters

    • state: any
    • context: any
    • nextBlock: NextBlock
    • isReplay: boolean

    Returns Promise<void>

handleBlock

  • handleBlock(nextBlock: NextBlock, isReplay: boolean): Promise<number | null>
  • Receive block, validate, and handle actions with updaters and effects

    Parameters

    • nextBlock: NextBlock
    • isReplay: boolean

    Returns Promise<number | null>

Protected handleWithState

  • handleWithState(handle: function): Promise<void>
  • Parameters

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

          • state: any
          • Optional context: any

          Returns void

    Returns Promise<void>

initialize

  • initialize(): Promise<void>
  • Performs all required initialization for the handler.

    Returns Promise<void>

Protected loadIndexState

  • loadIndexState(): Promise<IndexState>

Protected loadRanMigrations

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

migrate

  • migrate(sequenceName: string, pgp?: IDatabase<__type>, initial?: boolean): Promise<void>
  • Migrates the database by the given sequenceName. There must be a MigrationSequence with this name, or this will throw an error.

    Parameters

    • sequenceName: string

      The name of the MigrationSequence to be run.

    • Default value pgp: IDatabase<__type> = this.massiveInstance.instance
    • Default value initial: boolean = false

    Returns Promise<void>

Protected rollbackTo

  • rollbackTo(blockNumber: number): Promise<void>

Protected runEffects

  • runEffects(versionedActions: VersionedAction[], context: any, nextBlock: NextBlock): void
  • Process versioned actions against asynchronous side effects.

    Parameters

    • versionedActions: VersionedAction[]
    • context: any
    • nextBlock: NextBlock

    Returns void

Protected setup

  • setup(initSequenceName?: string): Promise<void>
  • Sets up the database by idempotently creating the schema, installing CyanAudit, creates internally used tables, and runs any initial migration sequences provided.

    Parameters

    • Default value initSequenceName: string = "init"

    Returns Promise<void>

Protected updateIndexState

  • updateIndexState(state: any, block: Block, isReplay: boolean, handlerVersionName: string): Promise<void>
  • Parameters

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

    Returns Promise<void>

Private warnOverwrite

  • warnOverwrite(db: any, toOverwrite: string): void