Skip to content

Conversation

@Hellobloc
Copy link

This PR is target to resolve issue-38.

Introduction

In the following code, your Project emit cachecontext twice which is not necessary and allowing emit same event twice.

// CacheContext returns a new Context with the multi-store cached and a new
// EventManager. The cached context is written to the context when writeCache
// is called. Note, events are automatically emitted on the parent context's
// EventManager when the caller executes the write.
func (c Context) CacheContext() (cc Context, writeCache func()) {
	cms := c.ms.CacheMultiStore()
	cc = c.WithMultiStore(cms).WithEventManager(NewEventManager())

	writeCache = func() {
		c.EventManager().EmitEvents(cc.EventManager().Events())
		cms.Write()
	}

	return cc, writeCache
}

func applyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error) {
// Add a panic safeguard
defer func() {
if recoveryError := recover(); recoveryError != nil {
printPanicRecoveryError(ctx, recoveryError)
err = errors.New("panic occurred during execution")
}
}()
// makes a new cache context, which all state changes get wrapped inside of.
cacheCtx, write := ctx.CacheContext()
err = f(cacheCtx)
if err != nil {
ctx.Logger().Error(err.Error())
} else {
// no error, write the output of f
write()
ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events())
}
return err
}

@Hellobloc
Copy link
Author

@rkollar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double Event Emit

1 participant