Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Dec 7, 2024
1 parent 732a480 commit 4829aca
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions core/services/relay/evm/read/multieventtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 27 in core/services/relay/evm/read/multieventtype.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

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)
}
}

Expand All @@ -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...)

Expand All @@ -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) {
Expand Down

0 comments on commit 4829aca

Please sign in to comment.