How can I do state manipulations independent of transactions // block handling

Starting from the sdk-application-tutorial it is easily possible to modify the handling of transactions, include new transactions etc…

I also want to modify what happens each block, in lotion.js there is the block handler for this, how is it possible with the Cosmos-SDK? It should only happen once each block and be independent of incoming txs

I found a solution:

So one has to set an EndBlock function in app.go like:

app.blaTerror is the function that one wants to execute at each block, an example can be seen in the commit. There just for testing a panic is caused, it should be panic(“penis”), the next commit resolves this mistake and works.

I don’t know if this is the intended way to to it, so if someone who is working on the SDK can comment, would be great still

Yes, that is exactly the way to do it - you can also run a function at the beginning of each block (before any transactions are processed) with app.SetBeginBlocker.

1 Like