Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Dec 9, 2024
1 parent f6786cd commit 6dda837
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions core/services/relay/evm/read/multieventtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,24 @@ type EventQuery struct {
func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (iter.Seq2[string, commontypes.Sequence], error) {
seqIter, err := multiEventTypeQueryWithoutErrorWrapping(ctx, lp, eventQueries, limitAndSort)
if err != nil {
return nil, newMultiEventTypeQueryError(eventQueries, err)
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 seqIter, nil
return seqIter, err
}

func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (iter.Seq2[string, commontypes.Sequence], error) {

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

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)
Expand All @@ -53,7 +67,7 @@ func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.L

remapped, remapErr := eq.EventBinding.remap(eq.Filter)
if remapErr != nil {
return nil, newMultiEventTypeQueryError(eventQueries, fmt.Errorf("error remapping filter: %w", remapErr))
return nil, fmt.Errorf("error remapping filter: %w", remapErr)
}
expressions = append(expressions, remapped.Expressions...)

Expand Down Expand Up @@ -83,25 +97,6 @@ func multiEventTypeQueryWithoutErrorWrapping(ctx context.Context, lp logpoller.L
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) {
type sequenceWithKey struct {
Key string
Expand Down

0 comments on commit 6dda837

Please sign in to comment.