diff --git a/packages/relayer/event.go b/packages/relayer/event.go index 5cfcf0ed96a..f2e8c9badcd 100644 --- a/packages/relayer/event.go +++ b/packages/relayer/event.go @@ -128,9 +128,9 @@ type FindAllByAddressOpts struct { // EventRepository is used to interact with events in the store type EventRepository interface { - Save(ctx context.Context, opts SaveEventOpts) (*Event, error) + Save(ctx context.Context, opts *SaveEventOpts) (*Event, error) UpdateStatus(ctx context.Context, id int, status EventStatus) error - UpdateFeesAndProfitability(ctx context.Context, id int, opts UpdateFeesAndProfitabilityOpts) error + UpdateFeesAndProfitability(ctx context.Context, id int, opts *UpdateFeesAndProfitabilityOpts) error FindAllByAddress( ctx context.Context, req *http.Request, diff --git a/packages/relayer/indexer/handle_chain_data_synced_event.go b/packages/relayer/indexer/handle_chain_data_synced_event.go index 86901e92f4f..8a05dcbbb14 100644 --- a/packages/relayer/indexer/handle_chain_data_synced_event.go +++ b/packages/relayer/indexer/handle_chain_data_synced_event.go @@ -52,7 +52,7 @@ func (i *Indexer) handleChainDataSyncedEvent( return errors.Wrap(err, "json.Marshal(event)") } - opts := relayer.SaveEventOpts{ + _, err = i.eventRepo.Save(ctx, &relayer.SaveEventOpts{ Name: relayer.EventNameChainDataSynced, Event: relayer.EventNameChainDataSynced, Data: string(marshaled), @@ -65,9 +65,7 @@ func (i *Indexer) handleChainDataSyncedEvent( SyncData: common.BytesToHash(event.Data[:]).Hex(), Kind: common.BytesToHash(event.Kind[:]).Hex(), SyncedInBlockID: event.Raw.BlockNumber, - } - - _, err = i.eventRepo.Save(ctx, opts) + }) if err != nil { return errors.Wrap(err, "i.eventRepo.Save") } diff --git a/packages/relayer/indexer/handle_message_status_changed_event.go b/packages/relayer/indexer/handle_message_status_changed_event.go index 4cf9ebffc04..df449e3a4f9 100644 --- a/packages/relayer/indexer/handle_message_status_changed_event.go +++ b/packages/relayer/indexer/handle_message_status_changed_event.go @@ -33,7 +33,7 @@ func (i *Indexer) handleMessageStatusChangedEvent( return nil } - _, err = i.eventRepo.Save(ctx, relayer.SaveEventOpts{ + _, err = i.eventRepo.Save(ctx, &relayer.SaveEventOpts{ Name: relayer.EventNameMessageStatusChanged, Data: string(marshaled), ChainID: chainID, diff --git a/packages/relayer/indexer/save_event_to_db.go b/packages/relayer/indexer/save_event_to_db.go index f261914af9d..08b485315a2 100644 --- a/packages/relayer/indexer/save_event_to_db.go +++ b/packages/relayer/indexer/save_event_to_db.go @@ -71,7 +71,7 @@ func (i *Indexer) saveEventToDB( opts.CanonicalTokenDecimals = canonicalToken.TokenDecimals() } - e, err := i.eventRepo.Save(ctx, opts) + e, err := i.eventRepo.Save(ctx, &opts) if err != nil { return 0, errors.Wrap(err, "svc.eventRepo.Save") } diff --git a/packages/relayer/pkg/http/get_events_by_address_test.go b/packages/relayer/pkg/http/get_events_by_address_test.go index 665ac21b354..8dae66921d1 100644 --- a/packages/relayer/pkg/http/get_events_by_address_test.go +++ b/packages/relayer/pkg/http/get_events_by_address_test.go @@ -17,7 +17,7 @@ import ( func Test_GetEventsByAddress(t *testing.T) { srv := newTestServer("") - _, err := srv.eventRepo.Save(context.Background(), relayer.SaveEventOpts{ + _, err := srv.eventRepo.Save(context.Background(), &relayer.SaveEventOpts{ Name: "name", Data: `{"Owner": "0x0000000000000000000000000000000000000123"}`, ChainID: big.NewInt(167001), diff --git a/packages/relayer/pkg/mock/event_repository.go b/packages/relayer/pkg/mock/event_repository.go index 6055a0771ef..29665c393b5 100644 --- a/packages/relayer/pkg/mock/event_repository.go +++ b/packages/relayer/pkg/mock/event_repository.go @@ -22,7 +22,7 @@ func NewEventRepository() *EventRepository { events: make([]*relayer.Event, 0), } } -func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts) (*relayer.Event, error) { +func (r *EventRepository) Save(ctx context.Context, opts *relayer.SaveEventOpts) (*relayer.Event, error) { r.events = append(r.events, &relayer.Event{ ID: rand.Int(), // nolint: gosec Data: datatypes.JSON(opts.Data), @@ -65,7 +65,7 @@ func (r *EventRepository) UpdateStatus(ctx context.Context, id int, status relay func (r *EventRepository) UpdateFeesAndProfitability( ctx context.Context, - id int, opts relayer.UpdateFeesAndProfitabilityOpts, + id int, opts *relayer.UpdateFeesAndProfitabilityOpts, ) error { var event *relayer.Event diff --git a/packages/relayer/pkg/repo/event.go b/packages/relayer/pkg/repo/event.go index 16d385c12d2..6a2b5d47f1a 100644 --- a/packages/relayer/pkg/repo/event.go +++ b/packages/relayer/pkg/repo/event.go @@ -28,7 +28,7 @@ func NewEventRepository(db DB) (*EventRepository, error) { }, nil } -func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts) (*relayer.Event, error) { +func (r *EventRepository) Save(ctx context.Context, opts *relayer.SaveEventOpts) (*relayer.Event, error) { e := &relayer.Event{ Data: datatypes.JSON(opts.Data), Status: opts.Status, @@ -62,7 +62,7 @@ func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts) func (r *EventRepository) UpdateFeesAndProfitability( ctx context.Context, id int, - opts relayer.UpdateFeesAndProfitabilityOpts, + opts *relayer.UpdateFeesAndProfitabilityOpts, ) error { e := &relayer.Event{} if err := r.db.GormDB().Where("id = ?", id).First(e).Error; err != nil { diff --git a/packages/relayer/pkg/repo/event_test.go b/packages/relayer/pkg/repo/event_test.go index cbcf840770e..f20880a16f6 100644 --- a/packages/relayer/pkg/repo/event_test.go +++ b/packages/relayer/pkg/repo/event_test.go @@ -118,12 +118,12 @@ func TestIntegration_Event_Save(t *testing.T) { assert.Equal(t, nil, err) tests := []struct { name string - opts relayer.SaveEventOpts + opts *relayer.SaveEventOpts wantErr error }{ { "success", - relayer.SaveEventOpts{ + &relayer.SaveEventOpts{ Name: "test", ChainID: big.NewInt(1), DestChainID: big.NewInt(2), @@ -184,7 +184,7 @@ func TestIntegration_Event_UpdateStatus(t *testing.T) { t.Run(tt.name, func(t *testing.T) { if tt.name == "success" { _, err := eventRepo.Save(context.Background(), - relayer.SaveEventOpts{ + &relayer.SaveEventOpts{ Name: "test", ChainID: big.NewInt(1), DestChainID: big.NewInt(2), @@ -223,7 +223,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) { addr := common.HexToAddress("0x71C7656EC7ab88b098defB751B7401B5f6d8976F") - _, err = eventRepo.Save(context.Background(), relayer.SaveEventOpts{ + _, err = eventRepo.Save(context.Background(), &relayer.SaveEventOpts{ Name: "name", Data: fmt.Sprintf(`{"Message": {"Owner": "%s"}}`, strings.ToLower(addr.Hex())), ChainID: big.NewInt(1), @@ -243,7 +243,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) { assert.Equal(t, nil, err) - _, err = eventRepo.Save(context.Background(), relayer.SaveEventOpts{ + _, err = eventRepo.Save(context.Background(), &relayer.SaveEventOpts{ Name: "name", Data: fmt.Sprintf(`{"Message": {"Owner": "%s"}}`, strings.ToLower(addr.Hex())), ChainID: big.NewInt(1), @@ -262,7 +262,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) { }) assert.Equal(t, nil, err) - _, err = eventRepo.Save(context.Background(), relayer.SaveEventOpts{ + _, err = eventRepo.Save(context.Background(), &relayer.SaveEventOpts{ Name: "name", Data: fmt.Sprintf(`{"Message": {"Owner": "%s"}}`, strings.ToLower(addr.Hex())), ChainID: big.NewInt(1), @@ -443,7 +443,7 @@ func TestIntegration_Event_FirstByMsgHash(t *testing.T) { eventRepo, err := NewEventRepository(db) assert.Equal(t, nil, err) - _, err = eventRepo.Save(context.Background(), relayer.SaveEventOpts{ + _, err = eventRepo.Save(context.Background(), &relayer.SaveEventOpts{ Name: "name", Data: fmt.Sprintf(`{"Message": {"Owner": "%s"}}`, strings.ToLower(addr.Hex())), ChainID: big.NewInt(1), diff --git a/packages/relayer/processor/is_profitable.go b/packages/relayer/processor/is_profitable.go index 13a80679d6f..2df6b39379b 100644 --- a/packages/relayer/processor/is_profitable.go +++ b/packages/relayer/processor/is_profitable.go @@ -59,7 +59,7 @@ func (p *Processor) isProfitable( EstimatedOnchainFee: estimatedOnchainFee, } - if err := p.eventRepo.UpdateFeesAndProfitability(ctx, id, opts); err != nil { + if err := p.eventRepo.UpdateFeesAndProfitability(ctx, id, &opts); err != nil { slog.Error("failed to update event", "error", err) } diff --git a/packages/relayer/processor/process_message.go b/packages/relayer/processor/process_message.go index e4d92e1da8e..4461cbf1f53 100644 --- a/packages/relayer/processor/process_message.go +++ b/packages/relayer/processor/process_message.go @@ -620,7 +620,7 @@ func (p *Processor) saveMessageStatusChangedEvent( // keep same format as other raw events data := fmt.Sprintf(`{"Raw":{"transactionHash": "%v"}}`, receipt.TxHash.Hex()) - _, err = p.eventRepo.Save(ctx, relayer.SaveEventOpts{ + _, err = p.eventRepo.Save(ctx, &relayer.SaveEventOpts{ Name: relayer.EventNameMessageStatusChanged, Data: data, EmittedBlockID: event.Raw.BlockNumber,