diff --git a/core/services/relay/evm/read/multieventtype.go b/core/services/relay/evm/read/multieventtype.go index d7c8ec46d92..291e1fec08f 100644 --- a/core/services/relay/evm/read/multieventtype.go +++ b/core/services/relay/evm/read/multieventtype.go @@ -24,30 +24,11 @@ type EventQuery struct { Address common.Address } -func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (sequences iter.Seq2[string, commontypes.Sequence], err error) { - defer func() { - if err != nil { - if len(eventQueries) > 0 { - var calls []Call - for _, eq := range eventQueries { - calls = append(calls, Call{ - ContractAddress: eq.Address, - ContractName: eq.EventBinding.contractName, - ReadName: eq.EventBinding.eventName, - ReturnVal: eq.SequenceDataType, - }) - } - - err = newErrorFromCalls(err, calls, "", eventReadType) - } else { - err = fmt.Errorf("no event queries provided: %w", err) - } - } - }() +func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (iter.Seq2[string, commontypes.Sequence], error) { for _, eq := range eventQueries { - if err = eq.EventBinding.validateBound(eq.Address); err != nil { - return nil, err + if err := eq.EventBinding.validateBound(eq.Address); err != nil { + return nil, newMultiEventTypeQueryError(eventQueries, err) } } @@ -63,7 +44,7 @@ func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueri remapped, remapErr := eq.EventBinding.remap(eq.Filter) if remapErr != nil { - return nil, fmt.Errorf("error remapping filter: %w", err) + return nil, newMultiEventTypeQueryError(eventQueries, fmt.Errorf("error remapping filter: %w", remapErr)) } expressions = append(expressions, remapped.Expressions...) @@ -82,10 +63,34 @@ func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueri logs, err := lp.FilteredLogs(ctx, []query.Expression{eventQuery}, limitAndSort, queryName) if err != nil { - return nil, wrapInternalErr(err) + return nil, newMultiEventTypeQueryError(eventQueries, wrapInternalErr(err)) + } + + seqIter, err := decodeMultiEventTypeLogsIntoSequences(ctx, logs, eventQueries) + if err != nil { + return nil, newMultiEventTypeQueryError(eventQueries, wrapInternalErr(err)) } - return decodeMultiEventTypeLogsIntoSequences(ctx, logs, eventQueries) + return seqIter, nil +} + +func newMultiEventTypeQueryError(eventQueries []EventQuery, err error) error { + if len(eventQueries) > 0 { + var calls []Call + for _, eq := range eventQueries { + calls = append(calls, Call{ + ContractAddress: eq.Address, + ContractName: eq.EventBinding.contractName, + ReadName: eq.EventBinding.eventName, + ReturnVal: eq.SequenceDataType, + }) + } + + err = newErrorFromCalls(err, calls, "", eventReadType) + } else { + err = fmt.Errorf("no event queries provided: %w", err) + } + return err } func decodeMultiEventTypeLogsIntoSequences(ctx context.Context, logs []logpoller.Log, eventQueries []EventQuery) (iter.Seq2[string, commontypes.Sequence], error) {