Created
November 15, 2017 10:50
-
-
Save nepalbitcoin/35a5f80d83e382189d7098a66467c8e5 to your computer and use it in GitHub Desktop.
go Ethereum console, start miner only when there's tx in pool & confirm. https://ethereum.stackexchange.com/a/3152 https://ethereum.stackexchange.com/questions/2531/common-useful-javascript-snippets-for-geth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var confirmBlocks =13; | |
var counter = confirmBlocks; | |
function checkWork(chx) { | |
if(chx == 0 && counter > 0){ //countdown | |
counter--; | |
return startMiner(counter); | |
}else if(chx == 1 && eth.getBlock("pending").transactions.length > 0){ //TX in POOL | |
counter = confirmBlocks; | |
return startMiner(counter); | |
}else{ | |
return stopMiner(counter); | |
} | |
} | |
function startMiner(counter){ | |
if (eth.mining) return true; | |
console.log("__Mining Started_"+counter); | |
return miner.start();; | |
} | |
function stopMiner(counter){ | |
if (!eth.mining) return true; | |
console.log("__Mining stopped_"+counter); | |
return miner.stop(); | |
} | |
eth.filter("latest", function(err, block) { | |
checkWork(0); | |
}); | |
eth.filter("pending", function(err, block) { | |
checkWork(1); | |
}); | |
checkWork(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment