Code Monkey home page Code Monkey logo

ethereumjs-blockchain's Introduction

SYNOPSIS

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

A module to store and interact with blocks.

INSTALL

npm install ethereumjs-blockchain

API

ethereumjs-blockchain

A module to store and interact with blocks

Blockchain

Implements functions for retrieving, manipulating and storing Ethereum'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 if any.

blockchain.getBlockInfo(hash, cb)

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
  • cb - the callback which is passed an Object containing two propties parent, the hash of the this block's parents and children an Array of hashes of children blocks.

blockchain.getBlockHashes(parentHash, count, cb)

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
  • cb - the callback which is give an array of block hashes

blockchain.getBlockChain(startingHashes, count, cb)

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, cb)

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

  • hashes - an Array hashes
  • cb - the callback

ethereumjs-blockchain's People

Contributors

kumavis avatar wanderer avatar axic avatar aakilfernandes avatar asinyagin avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar Michael Gord avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.