You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-6Lines changed: 60 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@
11
11
Event Scanner is a Rust library for streaming EVM-based smart contract events. It is built on top of the [`alloy`](https://github.com/alloy-rs/alloy) ecosystem and focuses on in-memory scanning without a backing database. Applications provide event filters; the scanner takes care of fetching historical ranges, bridging into live streaming mode, all whilst delivering the events as streams of data.
12
12
13
13
---
14
+
14
15
15
16
## Table of Contents
16
17
@@ -21,7 +22,7 @@ Event Scanner is a Rust library for streaming EVM-based smart contract events. I
@@ -32,6 +33,7 @@ Event Scanner is a Rust library for streaming EVM-based smart contract events. I
32
33
-**Historical replay** – stream events from past block ranges.
33
34
-**Live subscriptions** – stay up to date with latest events via WebSocket or IPC transports.
34
35
-**Hybrid flow** – automatically transition from historical catch-up into streaming mode.
36
+
-**Latest events fetch** – one-shot rewind to collect the most recent matching logs.
35
37
-**Composable filters** – register one or many contract + event signature pairs.
36
38
-**No database** – processing happens in-memory; persistence is left to the host application.
37
39
@@ -137,20 +139,71 @@ The flexibility provided by `EventFilter` allows you to build sophisticated even
137
139
138
140
### Scanning Modes
139
141
140
-
-**Live mode**–`start_scanner(BlockNumberOrTag::Latest, None)` subscribes to new blocks only.
141
-
-**Historical mode**–`start_scanner(BlockNumberOrTag::Number(start), Some(BlockNumberOrTag::Number(end)))`, scanner fetches events from a historical block range.
142
-
-**Historical → Live**–`start_scanner(BlockNumberOrTag::Number(start), None)` replays from `start` to current head, then streams future blocks.
142
+
-**Live mode**-`start_scanner(BlockNumberOrTag::Latest, None)` subscribes to new blocks only. On detecting a reorg, the scanner emits `ScannerStatus::ReorgDetected` and recalculates the confirmed window, streaming logs from the corrected confirmed block range.
143
+
-**Historical mode**-`start_scanner(BlockNumberOrTag::Number(start), Some(BlockNumberOrTag::Number(end)))`, scanner fetches events from a historical block range. While syncing ranges, the scanner verifies continuity. If a reorg is detected, it rewinds by `with_reorg_rewind_depth` blocks and resumes forward syncing.
144
+
-**Historical → Live**-`start_scanner(BlockNumberOrTag::Number(start), None)` replays from `start` to current head, then streams future blocks. Reorgs are handled as per the particular mode phase the scanner is in (historical or live).
143
145
144
146
For now modes are deduced from the `start` and `end` parameters. In the future, we might add explicit commands to select the mode.
145
147
146
148
See the integration tests under `tests/live_mode`, `tests/historic_mode`, and `tests/historic_to_live` for concrete examples.
147
149
150
+
### Scanning Latest Events
151
+
152
+
`scan_latest` collects the most recent matching events for each registered stream.
153
+
154
+
- It does not enter live mode; it scans a block range and then returns.
155
+
- Each registered stream receives at most `count` logs in a single message, chronologically ordered.
The scanner periodically checks the tip to detect reorgs. On reorg, the scanner emits `ScannerStatus::ReorgDetected`, resets to the updated tip, and restarts the scan. Final delivery to log listeners is in chronological order.
194
+
195
+
Notes:
196
+
197
+
- Ensure you create streams via `create_event_stream()` before calling `scan_latest*` so listeners are registered.
198
+
<!-- TODO: uncomment once implemented - The function returns after delivering the messages; to continuously stream new blocks, use `scan_latest_then_live`. -->
0 commit comments