/horoscope

Horoscope crawls data from Cosmos chains, stores and indexes everything into a MongoDB for easy access from clients.

Primary LanguageTypeScriptMIT LicenseMIT

Horoscope

Horoscope is an indexing service for Cosmos-based blockchain. It crawls data from the blockchain and index it into mongoDB. Based on the data, it can provide search functionality instead of querying data from LCD or RPC directly.

Currently, it supports network built by Cosmos SDK v0.45.1 or later. Supporting network:

Horoscope includes 2 main components:

  • Crawler: crawl data from the blockchain and index it into mongoDB
  • Backend API: provide search functionality through RESTful API

Main flow crawl

The crawl system divides the data into 2 parts:

  • Block data: the data in the block (block information, transaction, evidence)
  • State data: the data change in each state of the block (distribution, reward, delegation, community pool)

image

Most of the services are small Node applications written in Typescript. The Node services are built using Moleculerjs framework. With Crawler, we use Bull to manage the queue of crawling. High scalability is required for crawling, we use Redis Stream to implement Consumer Group pattern.

Architect backend api

image

List services (currently)

Install requirements

  • Redis: docker run --name redis -p 6379:6379 -d redis
  • MongoDB: docker run --name mongo -p 27017:27017 -d -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=xxx mongo
  • NPM: Horoscope currently use private packet aurajs to decode tx from Aura Network. To install aurajs, you must create a Personal Access Token has read package, put it to (xxx_xxx) on .npmrc file in root source code
@aura-nw:registry=https://npm.pkg.github.com/aura-nw
//npm.pkg.github.com/:_authToken=xxx_xxx

How to run

# create file env
cp .env.example .env
# then replace env field with your own value, point SERVICE to service you want to run

# run with moleculer cli
npm run dev

Configuration

Config file is located at .env, all service used moleculerJS Config, another config is custom:

environment variable description
CHAIN_ID Chain Id of Network want to be crawled (example: serenity-testnet-001).
ENABLE_LOADBALANCER Client Api used when get data from network, if yes use Resilent, if no use Axios . default: true

NPM scripts

  • npm run dev: Start development mode (load all services locally with hot-reload & REPL)
  • npm run start: Start production mode (set SERVICES env variable to load certain services)
  • npm run cli: Start a CLI and connect to production. Don't forget to set production namespace with --ns argument in script
  • npm run lint: Run ESLint
  • npm run ci: Run continuous test mode with watching
  • npm test: Run tests & generate coverage report
  • npm run dc:up: Start the stack with Docker Compose
  • npm run dc:down: Stop the stack with Docker Compose

Contributing

See CONTRIBUTING.md for details on how to contribute.