-
Notifications
You must be signed in to change notification settings - Fork 16
/
block.js
29 lines (22 loc) · 986 Bytes
/
block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
exports.BlockHeader = class BlockHeader {
constructor(version, previousBlockHeader, merkleRoot, time, nBits, nonce) {
// Version - at the time of writing there are 4 block versions.
this.version = version;
// previous block header hash - A SHA256(SHA256()) hash of previous block’s header. Ensures that previous block cannot be changed as this block needs to be changed as well.
this.previousBlockHeader = previousBlockHeader;
// merkle root hash - a merkle tree is a binary tree which holds all the hashed pairs of the tree.
this.merkleRoot = merkleRoot;
// a Unix epoch time when the miner started hashing the header.
this.time = time;
this.nonce = nonce; // Used in PoW
}
};
exports.Block = class Block {
constructor(blockHeader, index, txns) {
this.blockHeader = blockHeader;
// GenesisBlock is the first block - block 0
this.index = index;
// txns is the raw transaction in the block.
this.txns = txns;
}
};