juno icon indicating copy to clipboard operation
juno copied to clipboard

Add an event handlers interface in the worker

Open smallyunet opened this issue 1 year ago • 0 comments

Feature description

In our use case, we need to use different modules to handle tx.Events and distribute code logic based on different events, like this:

// in module A
func (m *Module) HandleTx(tx *juno.Transaction) error {
	for _, event := range tx.Events {
		if event.Type != "tx_log" {
			continue
		}

// in module B
func (m *Module) HandleTx(tx *juno.Transaction) error {
	for _, event := range tx.Events {
		if event.Type != "evm_tx_log" {
			continue
		}

So I think there needs to be an event handler in the Module interface?

Implementation proposal

After handle tx: https://github.com/forbole/juno/blob/cosmos/v0.50.x/parser/worker.go#L342

// call the event handlers
for i, event := range tx.Events {
	w.handEvnet(i, event)
}

Add a handleEvents method to allow the module to control the process based on events?

smallyunet avatar Jan 09 '25 04:01 smallyunet