From 7de644ed225d8d0117596b123c75aa31506e160d Mon Sep 17 00:00:00 2001 From: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:25:32 +0100 Subject: [PATCH] Receive log as values.Value to preserve type info --- core/capabilities/triggers/logevent/service.go | 5 +++-- core/capabilities/triggers/logevent/trigger.go | 2 +- .../cmd/capabilities/log-event-trigger/main.go | 18 +++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/capabilities/triggers/logevent/service.go b/core/capabilities/triggers/logevent/service.go index 7ed4855e097..e11324d89f9 100644 --- a/core/capabilities/triggers/logevent/service.go +++ b/core/capabilities/triggers/logevent/service.go @@ -83,7 +83,8 @@ func (s *TriggerService) Info(ctx context.Context) (capabilities.CapabilityInfo, // Register a new trigger // Can register triggers before the service is actively scheduling -func (s *TriggerService) RegisterTrigger(ctx context.Context, req capabilities.TriggerRegistrationRequest) (<-chan capabilities.TriggerResponse, error) { +func (s *TriggerService) RegisterTrigger(ctx context.Context, + req capabilities.TriggerRegistrationRequest) (<-chan capabilities.TriggerResponse, error) { if req.Config == nil { return nil, errors.New("config is required to register a log event trigger") } @@ -104,7 +105,7 @@ func (s *TriggerService) RegisterTrigger(ctx context.Context, req capabilities.T }) }) if !ok { - return nil, fmt.Errorf("cannot create new trigger since LogEventTriggerService has been stopped") + return nil, fmt.Errorf("cannot create new trigger since LogEventTriggerCapabilityService has been stopped") } if err != nil { return nil, fmt.Errorf("create new trigger failed %w", err) diff --git a/core/capabilities/triggers/logevent/trigger.go b/core/capabilities/triggers/logevent/trigger.go index 9a0e1d036c7..ed1e2fc9294 100644 --- a/core/capabilities/triggers/logevent/trigger.go +++ b/core/capabilities/triggers/logevent/trigger.go @@ -124,7 +124,7 @@ func (l *logEventTrigger) listen() { // Listen for events from lookbackPeriod var logs []types.Sequence var err error - logData := make(map[string]any) + var logData values.Value cursor := "" limitAndSort := query.LimitAndSort{ SortBy: []query.SortBy{query.NewSortByTimestamp(query.Asc)}, diff --git a/plugins/cmd/capabilities/log-event-trigger/main.go b/plugins/cmd/capabilities/log-event-trigger/main.go index 8abecf54aeb..55f2eb74ccd 100644 --- a/plugins/cmd/capabilities/log-event-trigger/main.go +++ b/plugins/cmd/capabilities/log-event-trigger/main.go @@ -20,9 +20,9 @@ const ( ) type LogEventTriggerGRPCService struct { - trigger capabilities.TriggerCapability - s *loop.Server - config logevent.Config + triggerService capabilities.TriggerCapability + s *loop.Server + config logevent.Config } func main() { @@ -69,7 +69,7 @@ func (cs *LogEventTriggerGRPCService) Name() string { } func (cs *LogEventTriggerGRPCService) Infos(ctx context.Context) ([]capabilities.CapabilityInfo, error) { - triggerInfo, err := cs.trigger.Info(ctx) + triggerInfo, err := cs.triggerService.Info(ctx) if err != nil { return nil, err } @@ -105,12 +105,16 @@ func (cs *LogEventTriggerGRPCService) Initialise( // Set relayer and trigger in LogEventTriggerGRPCService cs.config = logEventConfig - cs.trigger, err = logevent.NewTriggerService(ctx, cs.s.Logger, relayer, logEventConfig) + triggerService, err := logevent.NewTriggerService(ctx, cs.s.Logger, relayer, logEventConfig) if err != nil { - return fmt.Errorf("error creating new trigger for chainID %s: %v", logEventConfig.ChainID, err) + return fmt.Errorf("error creating trigger service for chainID %s: %v", logEventConfig.ChainID, err) + } + err = triggerService.Start(ctx) + if err != nil { + return fmt.Errorf("error starting trigger service for chainID %s: %v", logEventConfig.ChainID, err) } - if err := capabilityRegistry.Add(ctx, cs.trigger); err != nil { + if err := capabilityRegistry.Add(ctx, cs.triggerService); err != nil { return fmt.Errorf("error when adding cron trigger to the registry: %w", err) }