Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_: properly check type casts in activity service #6279

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions services/wallet/activity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ func (s *Service) FilterActivityAsync(requestID int32, addresses []common.Addres
if errors.Is(err, context.Canceled) || errors.Is(err, async.ErrTaskOverwritten) {
res.ErrorCode = ErrorCodeTaskCanceled
} else if err == nil {
activities := result.([]Entry)
res.Activities = activities
res.Offset = offset
res.HasMore = len(activities) == limit
res.ErrorCode = ErrorCodeSuccess
activities, ok := result.([]Entry)
if ok {
res.Activities = activities
res.Offset = offset
res.HasMore = len(activities) == limit
res.ErrorCode = ErrorCodeSuccess
}
}

sendResponseEvent(s.eventFeed, &requestID, EventActivityFilteringDone, res, err)
Expand Down Expand Up @@ -196,11 +198,13 @@ func (s *Service) GetActivityCollectiblesAsync(requestID int32, chainIDs []w_com
if errors.Is(err, context.Canceled) || errors.Is(err, async.ErrTaskOverwritten) {
res.ErrorCode = ErrorCodeTaskCanceled
} else if err == nil {
collectibles := result.([]CollectibleHeader)
res.Collectibles = collectibles
res.Offset = offset
res.HasMore = len(collectibles) == limit
res.ErrorCode = ErrorCodeSuccess
collectibles, ok := result.([]CollectibleHeader)
if ok {
res.Collectibles = collectibles
res.Offset = offset
res.HasMore = len(collectibles) == limit
res.ErrorCode = ErrorCodeSuccess
}
}

sendResponseEvent(s.eventFeed, &requestID, EventActivityGetCollectibles, res, err)
Expand Down Expand Up @@ -316,14 +320,19 @@ func (s *Service) GetRecipientsAsync(requestID int32, chainIDs []w_common.ChainI
result.Addresses, result.HasMore, err = GetRecipients(ctx, s.db, chainIDs, addresses, offset, limit)
return result, err
}, func(result interface{}, taskType async.TaskType, err error) {
res := result.(*GetRecipientsResponse)
res := &GetRecipientsResponse{
ErrorCode: ErrorCodeFailed,
}
if errors.Is(err, context.Canceled) || errors.Is(err, async.ErrTaskOverwritten) {
res.ErrorCode = ErrorCodeTaskCanceled
} else if err != nil {
res.ErrorCode = ErrorCodeFailed
} else if err == nil {
recipientsResponse, ok := result.(*GetRecipientsResponse)
if ok {
res = recipientsResponse
}
Comment on lines +328 to +332
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If err == nil and result can not be type asserted as * GetRecipientsResponse then this function will return :

&GetRecipientsResponse{
			ErrorCode: ErrorCodeFailed,
		}

Copy link
Contributor Author

@dlipicar dlipicar Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, it's basically the same behavior you get from the other functions, since for some reason you don't have a valid result you can return.

}

sendResponseEvent(s.eventFeed, &requestID, EventActivityGetRecipientsDone, result, err)
sendResponseEvent(s.eventFeed, &requestID, EventActivityGetRecipientsDone, res, err)
})
}

Expand All @@ -344,8 +353,11 @@ func (s *Service) GetOldestTimestampAsync(requestID int32, addresses []common.Ad
if errors.Is(err, context.Canceled) || errors.Is(err, async.ErrTaskOverwritten) {
res.ErrorCode = ErrorCodeTaskCanceled
} else if err == nil {
res.Timestamp = int64(result.(uint64))
res.ErrorCode = ErrorCodeSuccess
timestamp, ok := result.(uint64)
if ok {
res.Timestamp = int64(timestamp)
res.ErrorCode = ErrorCodeSuccess
}
}

sendResponseEvent(s.eventFeed, &requestID, EventActivityGetOldestTimestampDone, res, err)
Expand Down
Loading