Skip to content

Instantly share code, notes, and snippets.

@nepalbitcoin
Created November 15, 2017 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nepalbitcoin/35a5f80d83e382189d7098a66467c8e5 to your computer and use it in GitHub Desktop.
Save nepalbitcoin/35a5f80d83e382189d7098a66467c8e5 to your computer and use it in GitHub Desktop.
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