Skip to content

Commit 025a2b8

Browse files
LeoPatOZ0xNeshi
andauthored
Minor refactor (#115)
Co-authored-by: 0xNeshi <[email protected]>
1 parent 40d03cf commit 025a2b8

File tree

11 files changed

+240
-243
lines changed

11 files changed

+240
-243
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"rust-analyzer.cargo.features": ["test-utils"]
2+
"rust-analyzer.cargo.features": ["test-utils"],
3+
"rust-analyzer.rustfmt.extraArgs": ["+nightly"]
34
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ Create an event stream for the given event filters registered with the `EventSca
6161

6262
```rust
6363
use alloy::{eips::BlockNumberOrTag, network::Ethereum, sol_types::SolEvent};
64-
use event_scanner::{EventFilter, event_scanner::EventScanner, block_range_scanner::Error};
64+
use event_scanner::{EventFilter, EventScanner, EventScannerError, EventScannerMessage};
6565
use tokio_stream::StreamExt;
6666

6767
use crate::MyContract;
6868

6969
async fn run_scanner(
7070
ws_url: alloy::transports::http::reqwest::Url,
7171
contract: alloy::primitives::Address,
72-
) -> Result<(), Error> {
72+
) -> Result<(), EventScannerError> {
7373
let mut client = EventScanner::new().connect_ws::<Ethereum>(ws_url).await?;
7474

7575
let filter = EventFilter::new()
@@ -100,9 +100,9 @@ async fn run_scanner(
100100

101101
- `with_blocks_read_per_epoch` - how many blocks are read at a time in a single batch (taken into consideration when fetching historical blocks)
102102
- `with_reorg_rewind_depth` - how many blocks to rewind when a reorg is detected (NOTE ⚠️: still WIP)
103-
- `with_block_confirmations` - how many confirmations to wait for before considering a block final (NOTE ⚠️: still WIP)
103+
- `with_block_confirmations` - how many confirmations to wait for before considering a block final
104104

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).
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).
106106

107107
### Defining Event Filters
108108

@@ -140,7 +140,7 @@ The flexibility provided by `EventFilter` allows you to build sophisticated even
140140
### Scanning Modes
141141

142142
- **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.
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.
144144
- **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).
145145

146146
For now modes are deduced from the `start` and `end` parameters. In the future, we might add explicit commands to select the mode.

0 commit comments

Comments
 (0)