Skip to content

latest and sync::from_latest Should Allow Specifying "Anchor Event Filters" To Determine the Starting Point, But Stream Other Events #184

@0xNeshi

Description

@0xNeshi

Users need a way to establish a starting point for an event scanner based on one set of events, but then actually stream a different (or broader) set of events from that starting point forward.

Example API:

// these events are not streamed, only used as a starting point
let anchor_filter = EventFilter::new()
    .contract_address(addr)
    .event(Tracker::SIGNATURE);

// filter the latest 25 events from `anchor_filter`
let mut event_scanner = EventScanner::sync().from_latest(25, anchor_filter);

// Filter for inbox events (these are actually streamed).
let filter = EventFilter::new()
    .contract_address(self.config.inbox_address)
    .event(FirstEvent::SIGNATURE)
    .event(SecondEvent::SIGNATURE);

let mut stream = event_scanner.subscribe(filter);

Expected behavior for the above code:

  1. Scanner finds the 25th most recent Tracker event -> this determines the starting block
  2. Scanner then streams from that block forward:
    1. All FirstEvent events encountered from that point
    2. All SecondEvent events encountered from that point
  3. The initial Tracker events (set in anchor_filter ) are never emitted to the stream

It is important to include Clear documentation explaining the anchor vs stream filter distinction.


One of the users described a use case for this (paraphrasing):

I need to collect the first 100 Proposed events, but while collecting the first 100 Proposed events, I need the scanner to also stream the Proved events (no matter how many there are), and after collecting 100 Proposed events, live-stream both of these two events

The scanner would be configured similar to the previous example above:

let anchor_filter = EventFilter::new()
    .contract_address(addr)
    .event(Proposed::SIGNATURE);

let mut event_scanner = EventScanner::sync().from_latest(100, anchor_filter);

let filter = EventFilter::new()
    .contract_address(self.config.inbox_address)
    .event(Proposed::SIGNATURE)
    .event(Proved::SIGNATURE);

let mut stream = event_scanner.subscribe(filter);

Expected behavior for the above code:

  1. Scanner finds the 100th most recent Proposed event -> this determines the starting block
  2. Scanner then streams from that block forward:
    1. At most 100 Proposed events (since we started from the 100th)
    2. All Proved events encountered from that point

Related #180

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions