-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.js
33 lines (29 loc) · 921 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
30
31
32
33
const { GENESIS_DATA } = require('./config');
const cryptoHash = require('./crypto-hash')
class Block {
constructor ({timestamp,lastHash,hash,data}){
this.timestamp = timestamp;
this.lastHash = lastHash;
this.data= data;
this.hash = hash;
}
static genesis() {
return new this(GENESIS_DATA);
}
static minedBlock({lastBlock,data}){
const timestamp = Date.now
const lastHash = lastBlock.hash;
return new this(
{
timestamp,
lastHash,
data,
hash: cryptoHash(timestamp,lastHash,data)
}
);`
`
}
}
// const block1 = new Block({timestamp:'01/01/01',lastHash: 'foo-lasthash',hash:'foo-hash',data:'foo-data'});
// console.log('block1',block1)
module.exports = Block;