Last active
May 25, 2019 10:57
-
-
Save xavierlepretre/601ed5a9946e12108051e11599c89a36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
web3.eth.filter("pending").watch(function() { | |
if (eth.mining) return; | |
console.log(new Date() + "-- Transactions detected, so starting mining."); | |
miner.start(1); | |
}); | |
web3.eth.filter('latest', function(error, result) { | |
console.log(new Date() + "-- Got latest, so stopping mining"); | |
miner.stop(); | |
if (txpool.status.pending > 0) { | |
console.log(new Date() + "-- There were in fact pending transactions, so starting mining."); | |
miner.start(1); | |
} | |
}); | |
if (txpool.status.pending) { | |
console.log(new Date() + "-- Pending transactions on startup, so starting mining."); | |
miner.start(1); | |
} | |
console.log(new Date() + "-- Started on-demand mining. Watching txpool for pending Txs.."); | |
web3.eth.getBlockNumber(function(error, result) { | |
if (result.toString(10) == "0") { | |
console.log(new Date() + "-- empty chain. Mining first block"); | |
miner.start(1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use as in: