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

@gala-chain/stream

v0.0.1

Published

Streams blocks from GalaChain or Hyperledger Fabric network as RxJS Observables

Downloads

60

Readme

GalaChain Block Stream

A Node.js library to stream blocks from GalaChain or Hyperledger Fabric network as RxJS Observables.

Sample: Block stream

import stream from "@gala-chain/stream";

stream
  .connect(config)
  .channel("product-channel")
  .fromBlock(9)
  .subscribe({
    next: (block) => {
      console.log("Block:", block.blockNumber);
    },
    error: (err) => {
      console.error("Error:", err);
    },
    complete: () => {
      console.log("Stream completed");
    }
  });

Sample: Transaction stream

The previous sample connects to the network, subscribes to the product-channel channel, and starts streaming blocks from block number 9. It will get all transactions in the block, even invalid ones (e.g. those that failed with MVCC error). To get only valid transactions, you need to filter them out manually by transaction validation code.

Using that sample is also hard and non-performant to filter given transactions (e.g. by chaincode name). This is why we support also a way to get only transactions that are valid and match given criteria:

import stream from "@gala-chain/stream";

stream
  .connect(config)
  .channel("product-channel")
  .transactions(({ method }) => method === "GalaChainToken:TransferToken")
  .fromBlock(3)
  .subscribe({
    next: (tx) => {
      console.log("Transaction:", tx.id, "from block:", tx.blockNumber);
    },
    error: (err) => {
      console.error("Error:", err);
    },
    complete: () => {
      console.log("Stream completed");
    }
  });

Configuration

The config object should contain all the configuration needed to connect to the network. It can also be skipped to get default configuration, which is:

const config = {
  ca: {
    url: "https://localhost:7040",
    name: "ca.curator.local",
    orgMsp: "CuratorOrg"
  },
  user: {
    userId: "admin",
    userSecret: "adminpw"
  },
  peer: {
    url: "grpcs://localhost:7041",
    tlsCACertPath: "./test-chaincode/test-network/fablo-target/fabric-config/crypto-config/peerOrganizations/curator.local/msp/tlscacerts/tlsca.curator.local-cert.pem",
    grpcHostnameOverride: "peer0.curator.local"
  },
  stream: {
    chainInfoPollingIntervalMs: 2000,
    intervalMs: 1000,
    batchSize: 10,
    retryOnErrorDelayMs: 5000,
    maxRetryCount: 5
  }
};

See also the usage sample at ./src/sample-transactions.ts.

The end-to-end sample

This section describes how to create a GalaChain local network, fill it with some data and then stream blocks from it.

Step 1: Install the GalaChain CLI

npm install -g @gala-chain/cli

Step 2: Create a sample chaincode in the current directory

galachain init test-chaincode

Step 3: Start the network for test chaincode

(cd test-chaincode && npm run network:up)

Step 4: Run the e2e tests for the chaincode to populate the network with some data

(cd .. && npm run test:e2e --prefix test-chaincode)

Step 5: Stream blocks or transactions from the network

npx ts-node src/sample-blocks.ts

Or:

npx ts-node src/sample-transactions.ts

Once you're done, you can stop the network by running:

(cd test-chaincode && npm run network:prune)