pull down to refresh

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?
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.
Note that for *block topics, when the block chain tip changes, a reorganisation may occur and just the tip will be notified. It is up to the subscriber to retrieve the chain from the last known block to the new tip.
reply
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.
reply
A more accurate implementation would use the ZMQ to subscribe and get an event exactly when the new block is added. Polling getblockcount is still using normie-time as the basis for the sheduler.
Yea, I might have to vibe this one myself...
reply
0 sats \ 0 replies \ @dgy 10 Nov
I guess the easiest way to be notified about a new block is through bitcoind using the blocknotify property e.g. blocknotify=killall -USR1 datum_gateway
reply
Yeah, with the getblockcount command you gotta do some polling every few seconds and build your logic around that. It’s not the most elegant solution, but it works.
reply
I think just write a script that checks the blockheight and executes your code based on the block height ... then run that script with cron every minute or whatever
reply
to be clear, I think your idea to run code based on block height is a cool idea
reply