Skip to content

Commit

Permalink
Receive log as values.Value to preserve type info
Browse files Browse the repository at this point in the history
  • Loading branch information
kidambisrinivas committed Sep 30, 2024
1 parent 3e9e058 commit 7de644e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
18 changes: 11 additions & 7 deletions plugins/cmd/capabilities/log-event-trigger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 7de644e

Please sign in to comment.