Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit cached context events #13063

Merged
merged 19 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -39,7 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (x/authz) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) Add an allow list, an optional list of addresses allowed to receive bank assests via authz MsgSend grant.
* (context) [#13063](https://github.com/cosmos/cosmos-sdk/pull/13063) Implement `Context#CacheContextEmitEvents` which automatically emits all events emitted by the cached context when writing state.
* (x/authz) [#12648](https://github.com/cosmos/cosmos-sdk/pull/12648) Add an allow list, an optional list of addresses allowed to receive bank assets via authz MsgSend grant.
* (sdk.Coins) [#12627](https://github.com/cosmos/cosmos-sdk/pull/12627) Make a Denoms method on sdk.Coins.
* (testutil) [#12973](https://github.com/cosmos/cosmos-sdk/pull/12973) Add generic `testutil.RandSliceElem` function which selects a random element from the list.
* (x/authz) [#13047](https://github.com/cosmos/cosmos-sdk/pull/13047) Add a GetAuthorization function to the keeper.
Expand Down
15 changes: 15 additions & 0 deletions types/context.go
Expand Up @@ -275,6 +275,21 @@ func (c Context) CacheContext() (cc Context, writeCache func()) {
return cc, cms.Write
}

// CacheContextEmitEvents behaves the same as CacheContext except that it
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
// automatically emits the events from the cached context when the caller
// executes the writeCache function.
func (c Context) CacheContextEmitEvents() (cc Context, writeCache func()) {
cms := c.MultiStore().CacheMultiStore()
cc = c.WithMultiStore(cms).WithEventManager(NewEventManager())

writeCache = func() {
c.EventManager().EmitEvents(cc.EventManager().Events())
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
cms.Write()
}

return cc, writeCache
}

var _ context.Context = Context{}

// ContextKey defines a type alias for a stdlib Context key.
Expand Down