From 949ca2da1c154bc7a45809ee7302b326816da60e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 24 Jun 2015 07:22:10 -0400 Subject: [PATCH] fix mining script to work with both geth 0.9.33 and older versions --- js/mine.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/js/mine.js b/js/mine.js index 836f5dd9f..7c61b11ba 100644 --- a/js/mine.js +++ b/js/mine.js @@ -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)