fix mining script to work with both geth 0.9.33 and older versions

This commit is contained in:
Iuri Matias 2015-06-24 07:22:10 -04:00
parent 18dd35f1a5
commit 949ca2da1c
1 changed files with 25 additions and 10 deletions

View File

@ -1,20 +1,35 @@
setInterval(function() {
var miner_var;
if (admin.miner === undefined) {
miner_var = miner;
}
else {
miner_var = admin.miner;
}
var minimalAmount = (web3.eth.getBalance(web3.eth.coinbase) >= 1500000000000000000);
var pendingTransactions = web3.eth.pendingTransactions().length > 0;
if(!web3.eth.mining && (!minimalAmount || pendingTransactions)) {
if (!minimalAmount) { console.log("=== minimal ether amount not reached yet") }
if (pendingTransactions) { console.log("=== there are pending transactions") }
console.log("=== start mining");
admin.miner.start();
var pendingTransactions = function() {
if (web3.eth.pendingTransactions === undefined) {
return txpool.status.pending || txpool.status.queued;
}
else {
return web3.eth.pendingTransactions().length > 0;
}
}
else if (web3.eth.mining && minimalAmount && !pendingTransactions) {
if(!web3.eth.mining && (!minimalAmount || pendingTransactions())) {
if (!minimalAmount) { console.log("=== minimal ether amount not reached yet") }
if (pendingTransactions()) { console.log("=== there are pending transactions") }
console.log("=== start mining");
miner_var.start();
}
else if (web3.eth.mining && minimalAmount && !pendingTransactions()) {
if (minimalAmount) { console.log("=== minimal ether amount reached") }
if (!pendingTransactions) { console.log("=== no pending transactions") }
if (!pendingTransactions()) { console.log("=== no pending transactions") }
console.log("=== stop mining");
admin.miner.stop();
miner_var.stop();
}
}, 1000)