Hey builders,
I'm looking for a daemon cron-like job scheduler, but it works based on blocktime.
For example:
# run every block
* echo "New block found!"
# run every 3 blocks
*/3 echo "This block number evenly divides by 3"
# run on block 1,000,000
1000000 echo "Tick tock, bitcoin just found it's 1-millionth block!"Does something like this exist?
Never seen anything that does that. A few years back I made a daemon for Linux, it’s not that hard. For what you want, you can just use the command
bitcoin-cli getblockcount.A more accurate implementation would use the ZMQ to subscribe and get an event exactly when the new block is added. Polling
getblockcountis still using normie-time as the basis for the sheduler.Yea, I might have to vibe this one myself...
I guess the easiest way to be notified about a new block is through bitcoind using the
blocknotifyproperty e.g.blocknotify=killall -USR1 datum_gatewayYeah, with the
getblockcountcommand you gotta do some polling every few seconds and build your logic around that. It’s not the most elegant solution, but it works.There could be potential for some race conditions, like multiple blocks arrive at the same time or orphaned blocks/reorgs causing the same block to arrive multiple times, or blocks going down then up again.
https://bitcoincoredocs.com/zmq.html
👀 Inside Bitcoin Code ~ IBC#027 #1280777
Perfect timing indeed
I think just write a script that checks the blockheight and executes your code based on the block height ... then run that script with
cronevery minute or whateverto be clear, I think your idea to run code based on block height is a cool idea