Skip to content

Commit

Permalink
Simplify filter method
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Aug 12, 2021
1 parent f51ec67 commit 7fbf513
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk
var filteredEvents []sdk.Event
if err == nil {
commit()
filteredEvents = filterEvents(em.Events(), events)
filteredEvents = filterEvents(append(em.Events(), events...))
ctx.EventManager().EmitEvents(filteredEvents)
} // on failure, revert state from sandbox, and ignore events (just skip doing the above)

Expand Down Expand Up @@ -154,19 +154,12 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk
return rsp, nil
}

func filterEvents(events ...[]sdk.Event) []sdk.Event {
func filterEvents(events []sdk.Event) []sdk.Event {
// pre-allocate space for efficiency
cap := 0
for _, evts := range events {
cap += len(evts)
}
res := make([]sdk.Event, 0, cap)

for _, evts := range events {
for _, ev := range evts {
if ev.Type != "message" {
res = append(res, ev)
}
res := make([]sdk.Event, 0, len(events))
for _, ev := range events {
if ev.Type != "message" {
res = append(res, ev)
}
}
return res
Expand Down

0 comments on commit 7fbf513

Please sign in to comment.