2015-08-01 00:13:05 +00:00
|
|
|
var miner_var;
|
2015-05-24 13:04:44 +00:00
|
|
|
|
2015-08-01 00:13:05 +00:00
|
|
|
if (admin.miner === undefined) {
|
|
|
|
miner_var = miner;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
miner_var = admin.miner;
|
|
|
|
}
|
2015-06-24 11:22:10 +00:00
|
|
|
|
2015-08-01 00:13:05 +00:00
|
|
|
miner_var.setEtherbase(web3.eth.accounts[0]);
|
2015-05-24 13:36:19 +00:00
|
|
|
|
2015-08-01 00:13:05 +00:00
|
|
|
setInterval(function() {
|
2015-07-01 17:56:09 +00:00
|
|
|
var minimalAmount = (web3.eth.getBalance(web3.eth.coinbase) >= 15000000000000000000);
|
2015-06-24 11:22:10 +00:00
|
|
|
var pendingTransactions = function() {
|
2015-07-02 11:39:24 +00:00
|
|
|
if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {
|
2015-06-24 11:22:10 +00:00
|
|
|
return txpool.status.pending || txpool.status.queued;
|
|
|
|
}
|
2015-07-01 17:56:09 +00:00
|
|
|
else if (typeof web3.eth.pendingTransactions === "function") {
|
2015-06-24 11:22:10 +00:00
|
|
|
return web3.eth.pendingTransactions().length > 0;
|
|
|
|
}
|
2015-07-01 17:56:09 +00:00
|
|
|
else {
|
2015-07-02 11:39:24 +00:00
|
|
|
return web3.eth.pendingTransactions.length > 0 || web3.eth.getBlock('pending').transactions.length > 0;
|
2015-07-01 17:56:09 +00:00
|
|
|
}
|
2015-06-24 11:22:10 +00:00
|
|
|
}
|
2015-05-24 20:46:35 +00:00
|
|
|
|
2015-06-24 11:22:10 +00:00
|
|
|
if(!web3.eth.mining && (!minimalAmount || pendingTransactions())) {
|
2015-05-24 20:46:35 +00:00
|
|
|
if (!minimalAmount) { console.log("=== minimal ether amount not reached yet") }
|
2015-06-24 11:22:10 +00:00
|
|
|
if (pendingTransactions()) { console.log("=== there are pending transactions") }
|
2015-05-24 20:46:35 +00:00
|
|
|
console.log("=== start mining");
|
2015-06-24 11:22:10 +00:00
|
|
|
miner_var.start();
|
2015-05-24 13:04:44 +00:00
|
|
|
}
|
2015-06-24 11:22:10 +00:00
|
|
|
else if (web3.eth.mining && minimalAmount && !pendingTransactions()) {
|
2015-05-24 20:46:35 +00:00
|
|
|
if (minimalAmount) { console.log("=== minimal ether amount reached") }
|
2015-06-24 11:22:10 +00:00
|
|
|
if (!pendingTransactions()) { console.log("=== no pending transactions") }
|
2015-05-24 20:46:35 +00:00
|
|
|
console.log("=== stop mining");
|
2015-06-24 11:22:10 +00:00
|
|
|
miner_var.stop();
|
2015-05-24 13:04:44 +00:00
|
|
|
}
|
|
|
|
}, 1000)
|
|
|
|
|