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

@interlay/polkabtc-stats

v0.3.3

Published

This repository serves as a monitoring solution and API wrapper of ongoing events in the [PolkaBTC parachain](https://polkabtc.io/).

Downloads

94

Readme

PolkaBTC Stats API

This repository serves as a monitoring solution and API wrapper of ongoing events in the PolkaBTC parachain.

Monitoring

polkabtc-stats includes a service to extract all events from the BTC-Parachain into a PostgreSQL database for further processing.

When first starting, the service connects to a BTC-Parachain archive node to process all events from genesis and stores them into a PostgreSQL database. When it reaches the current block, it goes into a monitoring mode such that only the latest events from incoming blocks are parsed. On restarting, the service first checks the last processed block in the database and will continue to process events from blocks not yet in the database.

API wrapper

polkabtc-stats also provides an API wrapping around the PostgreSQL database, to aggregate and make available historic data about PolkaBTC parachain operation.

When the service is running, queries to the PostgreSQL database can be made. The package provides pre-defined views to display relevant statistics. This includes for example:

  • All issue requests
  • All redeem requests
  • Percentage of completed issue requests
  • Percentage of completed redeem requests

A note on decentralization

Anybody can freely host their own instance of this database and use it to serve a local version of the dashboards contained in the official PolkaBTC UI. Interlay is hosting its own version for monitoring purposes.

Usage

For the current instructions on running against a local parachain alongside the monitoring service, see the Testing section below.

Prerequisite: As the pg-native driver is used for the database, you need to ensure libpq is installed locally; on some systems, this may require installing the development version of relevant postgresql packages in addition to postgresql itself (e.g. libpq-dev or postgresql-libs-devel). See the NPM page for more details.

Ensure the proper environment variables for the PostgreSQL connection are set, e.g.:

PGHOST=yourhost
PGPORT=15432
PGDATABASE=database
PGUSER=youruser
PGPASSWORD=yourpassword

Start the service with:

export PGSSLMODE=require # for secure connections

yarn install
yarn build # generate the routes and run typechecking
yarn dev # start the server with file watching

Then navigate to localhost:3007/docs for the SwaggerUI, or to the defined routes to make use of the APIs.

Deployment

Run yarn start instead.

Client

For client generation, ensure java is in the path (this is not necessary just to run the stats server).

yarn client

This builds the client generated from the OpenAPI spec (which can then be published using yarn publish).

Testing

To build the database from the btc-parachain setup postgresql and run the included monitoring service.

docker run --rm --name postgres \
    -p 5432:5432 \
    -e POSTGRES_USER=user \
    -e POSTGRES_PASSWORD=password \
    postgres:11

export PGDATABASE="postgres"
export PGUSER="user"
export PGPASSWORD="password"

MONITOR=1 yarn dev

To persist the database, mount a local volume on the docker container.

mkdir -p $HOME/docker/volumes/postgres
docker run --rm --name postgres \
    -p 5432:5432 \
    -e POSTGRES_USER=user \
    -e POSTGRES_PASSWORD=password \
    -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data \
    postgres:11

Usage

import * as polkabtcStats from "@interlay/polkabtc-stats";
const statsApi = new polkabtcStats.StatsApi(new polkabtcStats.Configuration({ basePath: "http://localhost:3001" }));
const issues = (await statsApi.getTotalSuccessfulIssues()).data;

Autogenerated paths

src/ is the only directory containing hand-written code. Do not edit files in the other directories.

  • build/ contains the OpenAPI server (including the json definition and the routes to be served), generated from the definitons in src. Generated using yarn build.
  • client/ contains the generated typescript client, as an intermediate step in packaging the client.
  • dist/ contains the compiled client, publishable as an npm package. Generated (alongside client/) using yarn client.