GithubHelp home page GithubHelp logo

arkadiuszsz / substrate-events-listener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from substrate-developer-hub/substrate-events-listener

0.0 1.0 0.0 21 KB

Dockerized websocket listener for substrate events; also writes filtered event data to configured storage.

License: The Unlicense

Dockerfile 2.38% JavaScript 97.62%

substrate-events-listener's Introduction

Substrate Events Listener & Storage Adapter

A simple node.js based web-socket listener which subscribes to Parity Substrate runtime events and stores them in a data store. At the moment, MongoDB is supported but new stores can be added easily.

Substrate node and data sink related config lives in the .env file.

Why?

Ideally, we should avoid running iterators and loops on the on-chain data stored in a blockchain runtime or contracts. The chain should store the minimum amount of data which is needed for conflict resolution. Everything else can and should be stored off-chain with it's hash on the chain. In cases where on-chain data is stored in lists or maps and needs to be shown on a UI, an event based approach can be used to build an off-chain storage which can be queried from the UI.

This app listens to all Substrate runtime events using the web-socket connection, parses each event based on (extensible) custom rules and then stores the processed event data in one or more data stores. This off-chain storage can then be used for data analysis, querying, showing it on the UI, etc.

Usage

  1. Clone this repository.
  2. Make sure your Substrate node and MongoDB is running. Update the .env file with the server and ports, if needed.
  3. Set event section filters (comma separated list of module names, no spaces) in the .env file to filter events,
SUBSTRATE_EVENT_SECTIONS=all
SUBSTRATE_EVENT_SECTIONS=balances,assets,token
  1. Run the following docker command to build the image,
docker build -t substrate-listener .
  1. Run the following docker command to start the listener in a container,
docker run -d substrate-listener

Add new data stores

To use a new data store with the listener,

  1. Create the storage client in the adaptors dir (similar to existing mongo client)
  2. Add the connection config in .env and use it in the js client
  3. Import the new js client in dataService.js
  4. Use init() for initializing the client - connection, priming, etc.
  5. Use insert() for (of course) inserting substrate events data

Note

This app is not for production usage. It is mainly built to suggest an event based pattern for priming an off-chain storage. Please feel free to extend and use as needed.

substrate-events-listener's People

Contributors

gautamdhameja avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.