Created
April 1, 2016 01:51
-
-
Save niksmac/a22254ef5b6560cf584cb401d8b2b33d to your computer and use it in GitHub Desktop.
Ethereum Blockchain Mine only when there is a transaction
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 mining_threads = 1 | |
function checkWork() { | |
if (eth.getBlock("pending").transactions.length > 0) { | |
if (eth.mining) return; | |
console.log("== Pending transactions! Mining..."); | |
miner.start(mining_threads); | |
} else { | |
miner.stop(0); // This param means nothing | |
console.log("== No transactions! Mining stopped."); | |
} | |
} | |
eth.filter("latest", function(err, block) { checkWork(); }); | |
eth.filter("pending", function(err, block) { checkWork(); }); | |
checkWork(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment