Class: Block

Block

Block Instantiate a Block from a Buffer, JSON object, or Object with the properties of the Block

new Block(arg) → {Block}

Parameters:
Name Type Description
arg *

A Buffer, JSON string, or Object

Source:
Returns:
Type
Block

Members

blockheader :BlockHeader

Type:
Source:

blocksize :number

Type:
  • number
Source:

magicnum :number

Type:
  • number
Source:

nonce :number

Type:
  • number
Source:

size :number

Amount of bytes of the serialized block

Type:
  • number
Source:

timestamp :number

Type:
  • number
Source:

txs :Array.<Transaction>

Type:
Source:

version :number

Type:
  • number
Source:

Methods

<private, static> _from(arg) → {Object}

Parameters:
Name Type Description
arg *

A Buffer, JSON string or Object

Source:
Throws:
  • If the argument was not recognized
Type
TypeError
Returns:
  • An object representing block data
Type
Object

<private, static> _fromBufferReader(br) → {Object}

Parameters:
Name Type Description
br BufferReader

Block data

Source:
Returns:
  • An object representing the block data
Type
Object

<private, static> _fromJSON(data) → {Object}

Parameters:
Name Type Description
data String | Object

A JSON string or object

Source:
Returns:
  • An object representing block data
Type
Object

<static> fromBuffer(buf) → {Block}

Parameters:
Name Type Description
buf Buffer

A buffer of the block

Source:
Returns:
  • An instance of block
Type
Block

<static> fromBufferReader(br) → {Block}

Parameters:
Name Type Description
br BufferReader

A buffer reader of the block

Source:
Returns:
  • An instance of block
Type
Block

<static> fromJSON(json) → {Block}

Parameters:
Name Type Description
json String | Object

A JSON string or object

Source:
Returns:
  • An instance of block
Type
Block

<static> fromRawBlock(data) → {Block}

Parameters:
Name Type Description
data Binary

Raw block binary data or buffer

Source:
Returns:
  • An instance of block
Type
Block

<static> fromString(str) → {Block}

Parameters:
Name Type Description
str String

str - A hex encoded string of the block

Source:
Returns:
  • A hex encoded string of the block
Type
Block

_getHash() → {Buffer}

Source:
Returns:
  • The little endian hash buffer of the header
Type
Buffer

_setupProperties()

Internal function that sets up a some properties from blockheader for easier access

Source:

getMerkleRoot() → {Buffer}

Calculates the merkleRoot from the transactions.

Source:
Returns:
  • A buffer of the merkle root hash
Type
Buffer

getMerkleTree() → {Array}

Will build a merkle tree of all the transactions, ultimately arriving at a single point, the merkle root.

Source:
Returns:
  • An array with each level of the tree after the other.
Type
Array

getTransactionHashes() → {Array}

Will iterate through each transaction and return an array of hashes

Source:
Returns:
  • An array with transaction hashes
Type
Array

inspect() → {String}

Source:
Returns:
  • A string formated for the console
Type
String

toBuffer() → {Buffer}

Source:
Returns:
  • A buffer of the block
Type
Buffer

toBufferWriter(bw) → {BufferWriter}

Parameters:
Name Type Description
bw BufferWriter

An existing instance of BufferWriter

Source:
Returns:
  • An instance of BufferWriter representation of the Block
Type
BufferWriter

toJSON() → {String}

Source:
Returns:
  • A JSON string
Type
String

toObject() → {Object}

Source:
Returns:
  • A plain object with the block properties
Type
Object

toString() → {String}

Source:
Returns:
  • A hex encoded string of the block
Type
String

validMerkleRoot() → {Boolean}

Verifies that the transactions in the block match the blockheader merkle root

Source:
Returns:
  • If the merkle roots match
Type
Boolean