@wavesenterprise/waves-node-listener-service
v1.2.2
Published
Waves Node blockchain events listener and parser
Downloads
2
Readme
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