new Block(arg) → {Block}
Parameters:
| Name | Type | Description |
|---|---|---|
arg |
* | A Buffer, JSON string, or Object |
Returns:
- Type
- Block
Members
-
blockheader :BlockHeader
-
Type:
-
blocksize :number
-
Type:
- number
-
magicnum :number
-
Type:
- number
-
nonce :number
-
Type:
- number
-
size :number
-
Amount of bytes of the serialized block
Type:
- number
-
timestamp :number
-
Type:
- number
-
txs :Array.<Transaction>
-
Type:
- Array.<Transaction>
-
version :number
-
Type:
- number
Methods
-
<private, static> _from(arg) → {Object}
-
Parameters:
Name Type Description arg* A Buffer, JSON string or Object
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 brBufferReader Block data
Returns:
- An object representing the block data
- Type
- Object
-
<private, static> _fromJSON(data) → {Object}
-
Parameters:
Name Type Description dataString | Object A JSON string or object
Returns:
- An object representing block data
- Type
- Object
-
<static> fromBuffer(buf) → {Block}
-
Parameters:
Name Type Description bufBuffer A buffer of the block
Returns:
- An instance of block
- Type
- Block
-
<static> fromBufferReader(br) → {Block}
-
Parameters:
Name Type Description brBufferReader A buffer reader of the block
Returns:
- An instance of block
- Type
- Block
-
<static> fromJSON(json) → {Block}
-
Parameters:
Name Type Description jsonString | Object A JSON string or object
Returns:
- An instance of block
- Type
- Block
-
<static> fromRawBlock(data) → {Block}
-
Parameters:
Name Type Description dataBinary Raw block binary data or buffer
Returns:
- An instance of block
- Type
- Block
-
<static> fromString(str) → {Block}
-
Parameters:
Name Type Description strString str - A hex encoded string of the block
Returns:
- A hex encoded string of the block
- Type
- Block
-
_getHash() → {Buffer}
-
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
-
getMerkleRoot() → {Buffer}
-
Calculates the merkleRoot from the transactions.
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.
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
Returns:
- An array with transaction hashes
- Type
- Array
-
inspect() → {String}
-
Returns:
- A string formated for the console
- Type
- String
-
toBuffer() → {Buffer}
-
Returns:
- A buffer of the block
- Type
- Buffer
-
toBufferWriter(bw) → {BufferWriter}
-
Parameters:
Name Type Description bwBufferWriter An existing instance of BufferWriter
Returns:
- An instance of BufferWriter representation of the Block
- Type
- BufferWriter
-
toJSON() → {String}
-
Returns:
- A JSON string
- Type
- String
-
toObject() → {Object}
-
Returns:
- A plain object with the block properties
- Type
- Object
-
toString() → {String}
-
Returns:
- A hex encoded string of the block
- Type
- String
-
validMerkleRoot() → {Boolean}
-
Verifies that the transactions in the block match the blockheader merkle root
Returns:
- If the merkle roots match
- Type
- Boolean