0.0.3 • Published 4 months ago

@rsksmart/rsk-monitor v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

RSK Monitor

This project consists of a library intended to allow developers to integrate real-time blockchain monitoring and historical querying into their applications with just a few lines of code.

Installation

npm install @rsksmart/rsk-monitor

Project components

The main components of this library are the monitors, which are classes that offer extensive configuration possibilities to adapt to the necessities of the project integrating it. There are two types of monitors: real-time monitors, which allow analysis of each block/transaction at the moment it is mined, and historical monitors, which allow pulling data from previous transactions and blocks.

The configuration of the monitors consists of four types of classes that compose the monitor; each of these classes has a role in the analysis of the transactions:

ComponentDescriptionReal-timeHistorical
AlertsThis component allows triggering a notification using a specific publisher to alert the user when some specific pattern has occurred in the network.:white_check_mark::x:
HandlersThis component enables users to perform any action when a certain condition occurs. It serves as the primary component for those integrating the project who are not solely interested in monitoring.:white_check_mark::x:
MetricsThe metrics are components that store information about transactions and blocks, which can later be exported and analyzed.:white_check_mark::white_check_mark:
ExportersThe exporters are used to send the information gathered by the metrics to a specific output, such as a database, a visualization tool, or a client application.:white_check_mark::white_check_mark:

The project contains implementations of these components for the most common cases, such as tracking account balance, ERC20 balance, function executions, event emissions, etc. However, if the existing implementations don't fit the requirements, users can implement their own by implementing the corresponding interface and adding it to the monitor object. You can check the full list of existing implementations and interfaces in the API documentation

Analysis order

Depending on the component, the analysis can be performed at the block level or transaction level, and since each kind of component has a different priority level, they are always executed in the following order:

Transactions analysis order

  1. Alerts
  2. Handlers
  3. Metrics

Block analysis order

  1. Alerts
  2. Handlers
  3. Metrics
  4. Exporters

How to use

To use the library, you just need to configure and run the Monitor object. For this purpose, the library offers a builder for each monitor, making it easier to configure.

const nodeUrl = 'ws://localhost:4445/websocket'
const monitor = EvmMonitorBuilder.create({  rpcUrl: nodeUrl, reconnectSecondsInterval: 5 })
  .withBasicBlockMetrics()
  .withExporters(
    new ConsoleExporter(),
    new SqlExporter('postgres://postgres:test@db:5432/postgres', 'my-exporter')
  )
  .withBalanceTracking({ address: ADDRESS, alias: 'My address'})
  .withTransactionStatistics(MY_CONTRACT_ADDRESS)
  .withFullViewTracking('MyContract', MY_CONTRACT_ADDRESS, CONTRACT_ABI)
  .build()

monitor.run()

You can check the full list of builders and builder methods at the API documentation

How to run the tests

TODO uint test pending