Skip to content

Commit

Permalink
Refactored function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiDiachuk committed Mar 29, 2024
1 parent 03dd4cc commit d43b121
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions engine/access/state_stream/account_status_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,32 +190,21 @@ func (f *AccountStatusFilter) GroupCoreEventsByAccountAddress(events flow.Events

// addCoreEventFieldFilter adds a field filter for each core event type
func (f *AccountStatusFilter) addCoreEventFieldFilter(eventType flow.EventType, address string) error {
addFilter := func(field, value string) {
// Get the field associated with the event type from the defaultCoreEventsMap
fields, ok := defaultCoreEventsMap[string(eventType)]
if !ok {
return fmt.Errorf("unsupported event type: %s", eventType)
}

// Add the field filter for each field associated with the event type
for field := range fields {
if _, ok := f.EventFieldFilters[eventType]; !ok {
f.EventFieldFilters[eventType] = make(FieldFilter)
}
if _, ok := f.EventFieldFilters[eventType][field]; !ok {
f.EventFieldFilters[eventType][field] = make(map[string]struct{})
}
f.EventFieldFilters[eventType][field][value] = struct{}{}
}

switch eventType {
case CoreEventAccountCreated,
CoreEventAccountKeyAdded,
CoreEventAccountKeyRemoved,
CoreEventAccountContractAdded,
CoreEventAccountContractUpdated,
CoreEventAccountContractRemoved:
addFilter("address", address)
case CoreEventInboxValuePublished,
CoreEventInboxValueClaimed:
addFilter("provider", address)
addFilter("recipient", address)
case CoreEventInboxValueUnpublished:
addFilter("provider", address)
default:
return fmt.Errorf("unsupported event type: %s", eventType)
f.EventFieldFilters[eventType][field][address] = struct{}{}
}

return nil
Expand Down

0 comments on commit d43b121

Please sign in to comment.