-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminer.js
More file actions
26 lines (22 loc) · 814 Bytes
/
miner.js
File metadata and controls
26 lines (22 loc) · 814 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
const Wallet = require('../blockchain/wallet');
const Transaction = require('../blockchain/wallet/transaction')
class Miner {
constructor(blockchain, transactionPool, wallet, p2pServer){
this.blockchain = blockchain;
this.transactionPool = transactionPool;
this.wallet = wallet;
this.p2pServer = p2pServer;
}
mine (){
const validTransactions = this.transactionPool.validTransactions();
validTransactions.push(
Transaction.rewardTransaction(this.wallet, Wallet.blockchainWallet())
);
const block = this.blockchain.addBlock(validTransactions);
this.p2pServer.syncChains();
this.transactionPool.clear();
this.p2pServer.broadcastClearTransaction();
return block;
}
}
module.exports = Miner;