Skip to content
Cosmopediaby Unity Nodes
DiscussionsCosmos-SDKHow can I do state manipulations independent of transactions // block handlingForum ↗

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

Cosmos-SDK3 posts637 views1 likesLast activity Jan 2019
PW
pwiethOP
Jan 2019

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

PW
pwieth
Jan 2019

I found a solution:

github.com/DecentralCardGame/Cardchain patrickwieth

added Endblocker

changed 2 files with 18 additions and 2 deletions.

So one has to set an EndBlock function in app.go like:
app.SetEndBlocker(app.blaTerror)

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

CW
cwgoes
Jan 2019 1
pwieth:

So one has to set an EndBlock function in app.go like:
app.SetEndBlocker(app.blaTerror)

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.

← Back to Discussions