npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wavesenterprise/grpc-listener

v0.1.10

Published

### Config interface ```typescript export interface ConfigRpc { addresses: string[] // grpc node's addresses crtFile?: any // .pem file for tls (if enabled) logger: ILogger // logger auth: ApiKeyAuth | ServiceTokenAuth // auth connectionId?: str

Downloads

4

Readme

GRPC listener

Config interface

export interface ConfigRpc {
  addresses: string[] // grpc node's addresses
  crtFile?: any // .pem file for tls (if enabled)
  logger: ILogger // logger
  auth: ApiKeyAuth | ServiceTokenAuth // auth
  connectionId?: string // GRPC connectionId using in blockchain Node
  getLastBlocksSignature?: () => Promise<string> // function to get last block signature, if undefined => parse blockchain from begining
  asyncGrpc?: boolean // pause stream to avoid cache overflow, wait until 
  logTimers?: boolean // log different timers
  txLifetime?: number // cash tx lifetime
  filters?: {
    tx_types: number[] // tx types filter
  }
}

export interface ApiKeyAuth {
  nodeApiKey: string
}

export interface ServiceTokenAuth {
  serviceToken: string,
  authServiceAddress: string
}

Required functions

Need to implement such methods in your system

type RollbackLastBlock = () => Promise<any> // rollback last block
type RollbackToBlockSignature = (signature: string) => Promise<any> // rollback to specified block 
type ReceiveTxs = (block: NodeBlock, txs: ParsedIncomingGrpcTxType[]) => Promise<any> // take your transactions and block 

// optional
type ReceiveNewGrpcCall = (call: grpc.ClientReadableStream<any>) => any // take stream object if you need
type ReceiveCriticalError = (err: Error) => any // handle critical error (default - kill node.js process)

type OnHistorySynced = () => void // trigger when receive all HistoryBlocks

Example implementation

import { ParsedIncomingGrpcTxType } from '@wavesenterprise/js-sdk'
import { GrpcListener, ConfigRpc } from '@wavesenterprise/grpc-listener'

export class RPCSyncService {
  config: ConfigRpc
  listener: GrpcListener
  call: grpc.ClientReadableStream<any>

  constructor (readonly addresses: string[]) {
    const crt = GRPC_CERT_FILE_PATH && fs.readFileSync(GRPC_CERT_FILE_PATH)
    this.config = {
      addresses: this.addresses,
      crtFile: crt,
      logger,
      auth: NODE_API_KEY
        ? {nodeApiKey: NODE_API_KEY}
        : {serviceToken: SERVICE_TOKEN, authServiceAddress: AUTH_SERVICE_ADDRESS},
      asyncGrpc: ASYNC_GRPC,
      logTimers: true,
      txLifetime: TX_LIFETIME,
      getLastBlocksSignature: this.getLastBlocksSignature
    }
  }

  async start() {
    this.listener = new GrpcListener(this.config)
    await this.listener.listen(
      rollbackLastBlock: this.persistService.rollbackLastBlock,
      rollbackToBlockSignature: this.persistService.rollbackToBlockSignature,
      receiveTxs: this.receiveTxs,
      receiveCriticalError: this.receiveError,
      receiveNewGrpcCall: this.receiveNewGrpcCall,
      onHistorySynced: this.onHistorySynced
    )
  }

  onHistorySynced = () => {
    // blockchain parsed
  }

  receiveTxs = async (block: NodeBlock, txs: ParsedIncomingGrpcTxType[]) => {
    // take your txs here
  }

  receiveNewGrpcCall = (call: grpc.ClientReadableStream<any>) => {
    // take if you need
    this.call = call
  }

  getLastBlocksSignature = async () => {
    // TODO
    return Promise.resolve('test')
  }

  rollbackLastBlock = async () => {
    // TODO
    return Promise.resolve()
  }

  rollbackToBlockSignature = async (signature: string) => {
    // TODO
    return Promise.resolve()
  }

  receiveError = async (err: Error) => {
    console.trace(err);
    process.exit(1)
  }
}