-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.js
More file actions
32 lines (27 loc) · 660 Bytes
/
block.js
File metadata and controls
32 lines (27 loc) · 660 Bytes
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
30
31
32
// require GENESIS_DATA
const { GENESIS_DATA } = require("./config");
const cryptoHash = require("./crypto-hash");
class Block {
constructor({ timestamp, lastHash, hash, data }) {
this.timestamp = timestamp;
this.lastHash = lastHash;
this.hash = hash;
this.data = data;
}
// genesis block
static genesis() {
return new this(GENESIS_DATA);
}
static mineBlock({ lastBlock, data }) {
const timestamp = Date.now();
const lastHash = lastBlock.hash;
return new this({
timestamp,
lastHash,
data,
hash: cryptoHash(timestamp, lastHash, data),
});
}
}
// expot block
module.exports = Block;