Skip to content

Commit 088112d

Browse files
committed
update read me and doc test
1 parent 5072e58 commit 088112d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ event-scanner = "0.1.0-alpha.3"
5858
Create an event stream for the given event filters registered with the `EventScanner`:
5959

6060
```rust
61-
use alloy::{eips::BlockNumberOrTag, network::Ethereum, sol_types::SolEvent};
62-
use event_scanner::{EventFilter, event_scanner::EventScanner, block_range_scanner::Error};
61+
use alloy::{network::Ethereum, sol_types::SolEvent};
62+
use event_scanner::{EventFilter, event_scanner::EventScanner};
6363
use tokio_stream::StreamExt;
6464

6565
use crate::MyContract;
6666

6767
async fn run_scanner(
6868
ws_url: alloy::transports::http::reqwest::Url,
6969
contract: alloy::primitives::Address,
70-
) -> Result<(), Error> {
70+
) -> Result<(), Box<dyn std::error::Error>> {
7171
let mut client = EventScanner::new().connect_ws::<Ethereum>(ws_url).await?;
7272

7373
let filter = EventFilter::new()
@@ -76,9 +76,8 @@ async fn run_scanner(
7676

7777
let mut stream = client.create_event_stream(filter);
7878

79-
tokio::spawn(async move {
80-
client.start_scanner(BlockNumberOrTag::Earliest, Some(BlockNumberOrTag::Latest)).await
81-
});
79+
// Live mode with default confirmations
80+
tokio::spawn(async move { client.stream_live(Option::None).await });
8281

8382
while let Some(Ok(logs)) = stream.next().await {
8483
println!("Fetched logs: {logs:?}");
@@ -94,13 +93,16 @@ async fn run_scanner(
9493

9594
### Building a Scanner
9695

97-
`EventScanner` supports:
96+
- No builders. Pass parameters to each mode as options.
97+
- Defaults: `DEFAULT_BLOCKS_READ_PER_EPOCH`, `DEFAULT_BLOCK_CONFIRMATIONS`.
98+
- Connect with `connect_ws::<Ethereum>(url)`, `connect_ipc::<Ethereum>(path)`, or an existing provider.
9899

99-
- `with_blocks_read_per_epoch` - how many blocks are read at a time in a single batch (taken into consideration when fetching historical blocks)
100-
- `with_reorg_rewind_depth` - how many blocks to rewind when a reorg is detected (NOTE ⚠️: still WIP)
101-
- `with_block_confirmations` - how many confirmations to wait for before considering a block final (NOTE ⚠️: still WIP)
100+
Mode APIs (all optional params use sensible defaults):
101+
- Live: `client.stream_live(block_confirmations: Option<u64>)`
102+
- Historical: `client.stream_historical(start, end, reads_per_epoch: Option<usize>)`
103+
- From + Live: `client.stream_from(start, reads_per_epoch: Option<usize>, block_confirmations: Option<u64>)`
102104

103-
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+
Pass `None` to use defaults; provide values to override per call.
104106

105107
### Defining Event Filters
106108

@@ -136,13 +138,13 @@ The flexibility provided by `EventFilter` allows you to build sophisticated even
136138

137139
### Scanning Modes
138140

139-
- **Live mode**`start_scanner(BlockNumberOrTag::Latest, None)` subscribes to new blocks only.
140-
- **Historical mode**`start_scanner(BlockNumberOrTag::Number(start), Some(BlockNumberOrTag::Number(end)))`, scanner fetches events from a historical block range.
141-
- **Historical → Live**`start_scanner(BlockNumberOrTag::Number(start), None)` replays from `start` to current head, then streams future blocks.
141+
- **Live mode**`client.stream_live(None)` subscribes to new blocks using default confirmations.
142+
- **Historical mode**`client.stream_historical(start, end, None)` fetches a historical block range using the default batch size.
143+
- **Historical → Live**`client.stream_from(start, None, None)` replays from `start` to the confirmed tip, then streams future blocks with default confirmations.
142144

143-
For now modes are deduced from the `start` and `end` parameters. In the future, we might add explicit commands to select the mode.
145+
Override defaults by passing `Some(...)` for the optional parameters.
144146

145-
See the integration tests under `tests/live_mode`, `tests/historic_mode`, and `tests/historic_to_live` for concrete examples.
147+
See integration tests under `tests/live_mode`, `tests/historic_mode`, and `tests/historic_to_live` for concrete examples.
146148

147149
---
148150

src/block_range_scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! let client: BlockRangeScannerClient = block_range_scanner.run()?;
2828
//!
2929
//! // Live with confirmations (optional)
30-
//! let mut stream = client.stream_from(Some(5)).await?;
30+
//! let mut stream = client.stream_from(Some(BlockNumberOrTag::Number(5)), Option::None, Option::None).await?;
3131
//!
3232
//! while let Some(message) = stream.next().await {
3333
//! match message {

0 commit comments

Comments
 (0)