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
+87-49Lines changed: 87 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,6 @@
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
-
15
14
16
15
## Table of Contents
17
16
@@ -60,27 +59,29 @@ event-scanner = "0.3.0-alpha"
60
59
Create an event stream for the given event filters registered with the `EventScanner`:
-`EventScanner::sync()` – Processes historical data then transitions to live streaming
129
+
-`EventScanner::latest()` – Processes a specific number of events then optionally switches to live scanning mode
104
130
105
-
Once configured, connect using either `connect_ws::<Ethereum>(ws_url)` or `connect_ipc::<Ethereum>(path)`. This will `connect` the `EventScanner` and allow you to create event streams and start scanning in various [modes](#scanning-modes).
131
+
**Global Configuration Options:**
132
+
-`block_read_limit(usize)` – Sets the maximum number of blocks to process per read operation. This prevents RPC provider errors from overly large block range queries.
133
+
- Connect with `connect_ws::<Ethereum>(url)`, `connect_ipc::<Ethereum>(path)`, or `connect(provider)`.
134
+
135
+
**Starting the Scanner:**
136
+
Invoking `scanner.start()` starts the scanner in the specified mode.
106
137
107
138
### Defining Event Filters
108
139
@@ -111,70 +142,74 @@ Create an `EventFilter` for each event stream you wish to process. The filter sp
111
142
```rust
112
143
// Track a SPECIFIC event from a SPECIFIC contract
// Track ALL events from ALL contracts in the block range
133
164
letall_events_filter=EventFilter::new();
134
165
```
135
166
136
-
Register multiple filters by invoking `create_event_stream` repeatedly.
167
+
Register multiple filters by invoking `subscribe` repeatedly.
137
168
138
169
The flexibility provided by `EventFilter` allows you to build sophisticated event monitoring systems that can track events at different granularities depending on your application's needs.
139
170
140
171
### Scanning Modes
141
172
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. Currently no reorg logic has been implemented (NOTE ⚠️: still WIP). In the case that the end block > finalized block and you need reorg resistance, we recommend to use sync mode.
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).
173
+
-**Live mode** – `EventScanner::live()` creates a scanner that subscribes to new blocks as they arrive.
174
+
-**Historical mode** – `EventScanner::historic()` creates a scanner for processing historical block ranges.
175
+
-**Sync mode** – `EventScanner::sync()` creates a scanner that processes historical data then automatically transitions to live streaming.
176
+
-**Latest mode** – `EventScanner::latest()` creates a scanner that processes a set number of events.
145
177
146
-
For now modes are deduced from the `start` and `end` parameters. In the future, we might add explicit commands to select the mode.
178
+
**Configuration Tips:**
179
+
- Set `block_read_limit` based on your RPC provider's limits (e.g., Alchemy, Infura may limit queries to 2000 blocks)
180
+
- For live mode, if the WebSocket subscription lags significantly (e.g., >2000 blocks), ranges are automatically capped to prevent RPC errors
181
+
- Each mode has its own configuration options for start block, end block, confirmations, etc. where it makes sense
182
+
- The modes come with sensible defaults for example not specify a start block for historic mode automatically sets the start block to the earliest one
147
183
148
-
See the integration tests under `tests/live_mode`, `tests/historic_mode`, and `tests/historic_to_live` for concrete examples.
184
+
See integration tests under `tests/live_mode`, `tests/historic_mode`, and `tests/historic_to_live` for concrete examples.
149
185
150
186
### Scanning Latest Events
151
187
152
-
`scan_latest`collects the most recent matching events for each registered stream.
188
+
Scanner mode that collects a specified number of the most recent matching events for each registered stream.
153
189
154
190
- It does not enter live mode; it scans a block range and then returns.
155
191
- 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
232
195
233
Notes:
196
234
197
-
- Ensure you create streams via `create_event_stream()` before calling `scan_latest*` so listeners are registered.
235
+
- Ensure you create streams via `subscribe()` before calling `start` so listeners are registered.
198
236
<!-- TODO: uncomment once implemented - The function returns after delivering the messages; to continuously stream new blocks, use `scan_latest_then_live`. -->
0 commit comments