Skip to content

Commit

Permalink
chore(relayer): handle error and return point (#17682)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Jun 26, 2024
1 parent f095698 commit e99a860
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/relayer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type EventRepository interface {
ctx context.Context,
req *http.Request,
opts FindAllByAddressOpts,
) (paginate.Page, error)
) (*paginate.Page, error)
FirstByMsgHash(
ctx context.Context,
msgHash string,
Expand Down
8 changes: 4 additions & 4 deletions packages/relayer/pkg/mock/event_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *EventRepository) FindAllByAddress(
ctx context.Context,
req *http.Request,
opts relayer.FindAllByAddressOpts,
) (paginate.Page, error) {
) (*paginate.Page, error) {
type d struct {
Owner string `json:"Owner"`
}
Expand All @@ -119,12 +119,12 @@ func (r *EventRepository) FindAllByAddress(
for _, e := range r.events {
m, err := e.Data.MarshalJSON()
if err != nil {
return paginate.Page{}, err
return nil, err
}

data := &d{}
if err := json.Unmarshal(m, data); err != nil {
return paginate.Page{}, err
return nil, err
}

if data.Owner == opts.Address.Hex() {
Expand All @@ -133,7 +133,7 @@ func (r *EventRepository) FindAllByAddress(
}
}

return paginate.Page{
return &paginate.Page{
Items: events,
}, nil
}
Expand Down
9 changes: 6 additions & 3 deletions packages/relayer/pkg/repo/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *EventRepository) FindAllByAddress(
ctx context.Context,
req *http.Request,
opts relayer.FindAllByAddressOpts,
) (paginate.Page, error) {
) (*paginate.Page, error) {
pg := paginate.New(&paginate.Config{
DefaultSize: 100,
})
Expand Down Expand Up @@ -173,8 +173,11 @@ func (r *EventRepository) FindAllByAddress(
reqCtx := pg.With(q)

page := reqCtx.Request(req).Response(&[]relayer.Event{})
if page.Error {
return nil, page.RawError
}

return page, nil
return &page, nil
}

func (r *EventRepository) Delete(
Expand Down Expand Up @@ -246,7 +249,7 @@ func (r *EventRepository) FindLatestBlockID(
srcChainID uint64,
destChainID uint64,
) (uint64, error) {
q := `SELECT COALESCE(MAX(emitted_block_id), 0)
q := `SELECT COALESCE(MAX(emitted_block_id), 0)
FROM events WHERE chain_id = ? AND dest_chain_id = ? AND event = ?`

var b uint64
Expand Down

0 comments on commit e99a860

Please sign in to comment.