-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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:
- Scanner finds the 25th most recent
Trackerevent -> this determines the starting block - Scanner then streams from that block forward:
- All
FirstEventevents encountered from that point - All
SecondEventevents encountered from that point
- All
- The initial
Trackerevents (set inanchor_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
Proposedevents, but while collecting the first 100Proposedevents, I need the scanner to also stream theProvedevents (no matter how many there are), and after collecting 100Proposedevents, 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:
- Scanner finds the 100th most recent
Proposedevent -> this determines the starting block - Scanner then streams from that block forward:
- At most 100
Proposedevents (since we started from the 100th) - All
Provedevents encountered from that point
- At most 100
Related #180