OpenZeppelin / OpenZeppelin/Event-Scanner
`latest` and `sync::from_latest` Should Allow Specifying "Anchor Event Filters" To Determine the Starting Point, But Stream Other Events
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19
- Forks
- 7
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the EventScanner::sync, from_latest, subscribe, and EventFilter entry points, then review related issue #180. Implement the distinction between the anchor filter used to choose the starting block and the stream filter used for emitted events, and document that distinction clearly. Done means the stated Proposed/Proved and Tracker/inbox behaviors are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100