forked from ac12644/Blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.js
28 lines (21 loc) · 1012 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
exports.BlockHeader = class BlockHeader {
constructor(version, previousBlockHeader, merkleRoot, time, nBits, nounce) {
// 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;
}
};
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;
}
}