1.0.6 • Published 6 months ago

signum-chain-walker v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Coverage Maintainability Rating Vulnerabilities Code Smells Bugs

signum-chain-walker

This is a reusable NodeJS server that listens to blocks/transactions and/or walks over the chain. Useful, if you need to react on transactions or want to make analysis of the ledgers data.


Quick Start

Just install using either npm i signum-chain-walker or yarn add signum-chain-walker

Example

Listen to the Signum blocks and/or transactions

const walker = new ChainWalker({
  nodeHost: "http://localhost:6876",
})
  // handlers can be asynchronous or synchronous
  .onBlock(async (block) => {
    await sleep(100); // simulate an async task
    console.log("Block #", block.height);
  })
  .onTransaction((tx) => {
    console.log("Transaction #", tx.transaction);
  });

(async () => {
  await walker.listen();
})();

Example Collecting Data

const StartBlock = 552_000;
let countedBlocks = 0;
let countedTransactions = 0;
let movedSigna = Amount.Zero();

const walker = new ChainWalker({ nodeHost: "http://localhost:6876" })
  .onBlock(() => {
    countedBlocks++;
  })
  .onTransaction((tx) => {
    countedTransactions++;
    movedSigna.add(Amount.fromPlanck(tx.amountNQT));
  });

(async () => {
  await walker.walk(StartBlock);
  console.log(
    `Counted ${countedTransactions} transactions since Block ${StartBlock} (in ${countedBlocks} blocks)`
  );
  console.log(`${movedSigna} were moved`);
  console.log(
    `This is ${movedSigna.clone().divide(countedTransactions)} per tx`
  );
  console.log(`This is ${movedSigna.clone().divide(countedBlocks)} per block`);
  process.exit(0); // graceful shutdown
})();

Documentation

Full documentation can be found here: Documentation

Examples

Look into the examples folder for fully functional code.

You can run the examples using:

  • npm run example:listen
  • npm run example:walk
  • npm run example:walk-listen
  • npm run example:account-listen
1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

7 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago