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

icjs-blockchain

v0.0.1

Published

A module to store and interact with blocks

Downloads

14

Readme

SYNOPSIS

NPM Package Build Status Coverage Status Gitter or #icjs on freenode

A module to store and interact with blocks.

INSTALL

npm install icjs-blockchain

API

icjs-blockchain

A module to store and interact with blocks

Blockchain

Implements functions for retrieving, manipulating and storing HappyUC's blockchain

new Blockchain(opts)

Creates new Blockchain object

  • opts.blockDB - the database where Blocks are stored and retreived by hash. Should be a levelup instance.
  • opts.detailsDB - the database where Block number resolutions and other metadata is stored. Should be a levelup instance.
  • opts.validate - this the flag to validate blocks (e.g. Proof-of-Work).

BlockChain Properties

  • head - The Head, the block that has the most weight
  • parentHead- The parent of the head block
  • genesisHash - The hash of the genesis block
  • height - The height of the blockchain
  • totallDifficulty - The totall difficulty which is the some of a the difficulty of all the prevous blocks

BlockChain methods

blockchain.putBlock(block, callback)

Adds a block to the blockchain.

  • block - the block to be added to the blockchain
  • callback - the callback. It is given two parameters err and the saved block

blockchain.getBlock(blockTag, callback)

Gets a block by its blockTag.

  • blockTag - the block's hash or number
  • callback - the callback. It is given two parameters err and the found block (an instance of https://github.com/icjs/icjs-block) if any.

blockchain.getDetails(hash, callback)

Retrieves meta infromation about the block and passed it to the callback

  • hash - the hash of the block as a Buffer or a hex String
  • callback - the callback which is passed an Object containing the following properties:
    • parent - the hash of the parent block
    • td - the total difficulty of the block
    • number - the block number
    • child - the block's children
    • genesis - boolean (true if genesis block, false if not)
    • inChain - TODO
    • staleChildren - TODO

blockchain.getBlockHashes(parentHash, count, callback)

Gets a segment of the blockchain starting at the parent hash and contuning for count blocks returning an array of block hashes orders from oldest to youngest.

  • parentHash - the block to start from. Given as a Buffer or a hex String
  • count - a Number specifing how many block hashes to return
  • callback - the callback which is give an array of block hashes

blockchain.getBlockChain(startingHashes, count, callback)

gets a section of the blockchain in a form of an array starting at the parent hash, up count blocks

  • startingHashes - an array of hashes or a single hash to start returning the chain from. The first hash in the array that is found in the blockchain will be used.
  • count - the max number of blocks to return
  • callback - the callback. It is given two parameters err and blockchain. err is any errors. If none of the starting hashes were found err will be notFound. blockchain is an array of blocks.

blockchain.selectNeededHashes(hashes, callback)

Given an ordered array, returns to the callback an array of hashes that are not in the blockchain yet.

  • hashes - an Array hashes
  • callback - the callback