Check transactions in the background

Is there a possibility to run a javascript function in the backround, while running geth?
I mean: when there is a pending transaction, let's run miners, otherwise not.

So: I would like to run this script in the background; how to do it?
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();
        console.log("== No transactions! Mining stopped.");
    }
}

eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });

checkWork();

Best Answer

Sign In or Register to comment.