@wavesenterprise/waves-node-listener-service
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Waves blockchain node listener

Install

$ npm i @wavesenterprise/waves-node-listener-service

or

$ yarn add @wavesenterprise/waves-node-listener-service

Use

// app.module.ts
import { WavesNodeListenerModule } from '@wavesenterprise/we-node-grpc-api-nest'
import { AppService } from './app.service'

@Module({
  imports: [
    WavesNodeListenerModule.forRoot({
      blockchainStreamAddress: 'nodes-testnet.wavesnodes.com:6881',
      reconnectDelay: 5000,
      reconnectOnClose: true,
      reconnectOnError: false,
      // Dead connection checks time since last received message
      deadConnectionCheckInterval: 5000,
      deadConnectionTimeout: 60000,
      reconnectOnDeadConnection: true,
    })
  ],
  providers: [AppService],
})
export class AppModule {
}
// app.service.ts
import { WavesNodeListenerService } from '@wavesenterprise/waves-node-listener-service'
import { Injectable, OnApplicationBootstrap } from '@nestjs/common'

@Injectable()
export class AppService implements OnApplicationBootstrap {

  constructor(
    private readonly nodeListenerService: WavesNodeListenerService,
  ) {
  }

  async onApplicationBootstrap() {
    this.nodeListenerService.on('block', (data) => {
      this.nodeListenerService.setLastProcessedBlock(data.height)
    })
    this.nodeListenerService.on('microblock', (data) => {
      // process microblock (optional)
    })
    this.nodeListenerService.on('rollbackCompleted', (data) => {
      // delete rollbacked data 
    })
    await this.nodeListenerService.connect()
  }
}

Notes

Also emits raw stream events:
close
error
pause
resume
data

If deadConnectionTimeout and deadConnectionCheckInterval props are set, emits dead event

Dependents (0)

Package Sidebar

Install

npm i @wavesenterprise/waves-node-listener-service

Weekly Downloads

0

Version

1.2.2

License

MIT

Unpacked Size

110 kB

Total Files

23

Last publish

Collaborators

  • stfy
  • sergeymart
  • nbugaev
  • wavesadmin
  • aklyavlin
  • dimalitvinov
  • mikhail.milekhin