-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminer.js
More file actions
34 lines (31 loc) · 707 Bytes
/
miner.js
File metadata and controls
34 lines (31 loc) · 707 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
33
34
/**
* Miner implementation
*
* @class Miner
*/
class Miner {
/**
* Creates an instance of Miner.
*
* @param {Blockchain} blockchain Blockchain instance
* @memberof Miner
*/
constructor (blockchain) {
this.blockchain = blockchain
}
/**
* Mine
*
* @param {string} recipientAddress Recipient address
* @returns {Block} Mined block
* @memberof Miner
*/
mine (recipientAddress) {
let lastBlock = this.blockchain.lastBlock()
let lastProof = lastBlock.proof
let proof = this.blockchain.proofOfWork(lastProof)
this.blockchain.addTranstacion('', recipientAddress, 1)
return this.blockchain.createBlock(proof)
}
}
module.exports = Miner