Skip to content

Commit

Permalink
Set cursor direction in Log Event Trigger Capability (#14691)
Browse files Browse the repository at this point in the history
* Set cursor direction

* Make query count configurable
  • Loading branch information
kidambisrinivas authored Oct 8, 2024
1 parent 910e65f commit 736b655
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
Network string `json:"network"`
LookbackBlocks uint64 `json:"lookbakBlocks"`
PollPeriod uint32 `json:"pollPeriod"`
QueryCount uint64 `json:"queryCount"`
}

func (config Config) Version(capabilityVersion string) string {
Expand Down
7 changes: 6 additions & 1 deletion core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func newLogEventTrigger(ctx context.Context,
callbackCh := make(chan capabilities.TriggerResponse, defaultSendChannelBufferSize)
ticker := time.NewTicker(time.Duration(logEventConfig.PollPeriod) * time.Millisecond)

if logEventConfig.QueryCount == 0 {
logEventConfig.QueryCount = 20
}

// Initialise a Log Event Trigger
l := &logEventTrigger{
ch: callbackCh,
Expand Down Expand Up @@ -120,6 +124,7 @@ func (l *logEventTrigger) listen() {
cursor := ""
limitAndSort := query.LimitAndSort{
SortBy: []query.SortBy{query.NewSortByTimestamp(query.Asc)},
Limit: query.Limit{Count: l.logEventConfig.QueryCount},
}
for {
select {
Expand All @@ -134,7 +139,7 @@ func (l *logEventTrigger) listen() {
"startBlockNum", l.startBlockNum,
"cursor", cursor)
if cursor != "" {
limitAndSort.Limit = query.Limit{Cursor: cursor}
limitAndSort.Limit = query.CursorLimit(cursor, query.CursorFollowing, l.logEventConfig.QueryCount)
}
logs, err = l.contractReader.QueryKey(
ctx,
Expand Down

0 comments on commit 736b655

Please sign in to comment.