embark-area-51/js/mine.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

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-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() {
var minimalAmount = (web3.eth.getBalance(web3.eth.coinbase) >= 15000000000000000000);
var pendingTransactions = function() {
if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {
return txpool.status.pending || txpool.status.queued;
}
else if (typeof web3.eth.pendingTransactions === "function") {
return web3.eth.pendingTransactions().length > 0;
}
else {
return web3.eth.pendingTransactions.length > 0 || web3.eth.getBlock('pending').transactions.length > 0;
}
}
2015-05-24 20:46:35 +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") }
if (pendingTransactions()) { console.log("=== there are pending transactions") }
2015-05-24 20:46:35 +00:00
console.log("=== start mining");
miner_var.start();
2015-05-24 13:04:44 +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") }
if (!pendingTransactions()) { console.log("=== no pending transactions") }
2015-05-24 20:46:35 +00:00
console.log("=== stop mining");
miner_var.stop();
2015-05-24 13:04:44 +00:00
}
}, 1000)