Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
5f92f5c
feat: add backon library
LeoPatOZ Oct 16, 2025
2ad6516
feat: add provider wrapper
LeoPatOZ Oct 16, 2025
41824f0
Merge branch 'main' into retry-logic
LeoPatOZ Oct 16, 2025
22c2448
feat: use internal
LeoPatOZ Oct 16, 2025
d738ab2
feat: add get logs to safe provider
LeoPatOZ Oct 16, 2025
d068c8e
chore: made var public
LeoPatOZ Oct 16, 2025
d1e12e5
feat: added safe provider conifgs to block range scanner
LeoPatOZ Oct 16, 2025
0e9aa3b
feat: use safe provider in event scanner
LeoPatOZ Oct 16, 2025
319940a
feat: undo safe provider errors
LeoPatOZ Oct 16, 2025
65527b8
feat: implement stream block
LeoPatOZ Oct 20, 2025
b5bf428
test: add basic testing to safe provider
LeoPatOZ Oct 20, 2025
6241e83
chore: delete other constants
LeoPatOZ Oct 20, 2025
e24a6f7
Merge branch 'main' into retry-logic
LeoPatOZ Oct 20, 2025
79eaaae
fix: fmt
LeoPatOZ Oct 20, 2025
112c860
feat: add logging to rpc calls
LeoPatOZ Oct 21, 2025
9fc6543
chore: add comments and rename timeout
LeoPatOZ Oct 21, 2025
8bd13b1
chore: doctest
LeoPatOZ Oct 21, 2025
af7ce01
feat: add total timeout
LeoPatOZ Oct 21, 2025
c1ff8b5
Merge branch 'main' into retry-logic
LeoPatOZ Oct 23, 2025
471f767
ref: imporving tracing message
LeoPatOZ Oct 23, 2025
855e167
ref: collapse timeout fn to one
LeoPatOZ Oct 23, 2025
ff40e8a
ref: better syntax
LeoPatOZ Oct 23, 2025
992853c
ref: remove with and address default nit
LeoPatOZ Oct 23, 2025
ab35dc5
fix: doctest
LeoPatOZ Oct 23, 2025
cdf9b95
Update src/safe_provider.rs
LeoPatOZ Oct 23, 2025
3c0a971
Merge remote-tracking branch 'refs/remotes/origin/retry-logic' into r…
LeoPatOZ Oct 23, 2025
74cd3d7
ref: use atomic usize
LeoPatOZ Oct 23, 2025
41cc733
ref: update test to match for error
LeoPatOZ Oct 23, 2025
4af01ab
ref: update doc
LeoPatOZ Oct 23, 2025
3e32b8e
Merge branch 'main' into retry-logic
LeoPatOZ Oct 23, 2025
3329c38
fix: merge errors with connect methods
LeoPatOZ Oct 23, 2025
586b03e
fix: root --> safe provider
LeoPatOZ Oct 23, 2025
8a080e4
ref: tracing update
LeoPatOZ Oct 23, 2025
982ea96
ref: remove doc
LeoPatOZ Oct 23, 2025
f51c107
feat: add fallbackprovider
LeoPatOZ Oct 27, 2025
49f06bc
ref: avoid clone provider when possible
LeoPatOZ Oct 27, 2025
7d1572d
Merge branch 'retry-logic' into multiple-provider
LeoPatOZ Oct 27, 2025
9566f51
ref: import
LeoPatOZ Oct 27, 2025
c87251f
feat: add list of providers
LeoPatOZ Oct 27, 2025
a0d3087
feat: update to add fallback provider to main scanners
LeoPatOZ Oct 27, 2025
919d352
fix: doctest
LeoPatOZ Oct 27, 2025
c6693e7
ref: better logging
LeoPatOZ Oct 27, 2025
6d2b943
fix: test uses anvil (mock provider does not support pubsub)
LeoPatOZ Oct 27, 2025
cd1a2d9
fix: format
LeoPatOZ Oct 27, 2025
0546feb
ref: update test
LeoPatOZ Oct 27, 2025
01a9cf1
feat: add custom error for safe provider
LeoPatOZ Oct 27, 2025
a82b12f
ref: remove moves
LeoPatOZ Oct 27, 2025
6c995a2
Merge branch 'main' into retry-logic
LeoPatOZ Oct 27, 2025
06e50e2
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 27, 2025
4264914
fix: update test post merge
LeoPatOZ Oct 27, 2025
72b8eaf
ref: remove filter clone
LeoPatOZ Oct 27, 2025
1ee07ca
ref: rename safe to robust provider
LeoPatOZ Oct 28, 2025
c2fe8b7
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 28, 2025
f2b6d47
ref: comment
LeoPatOZ Oct 28, 2025
d7ea449
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 28, 2025
9bae33b
fix: rename
LeoPatOZ Oct 28, 2025
f622b21
feat: move block not found to provider
LeoPatOZ Oct 28, 2025
058a3ed
fix: doc test
LeoPatOZ Oct 28, 2025
14ed0e4
ref: use matches
LeoPatOZ Oct 28, 2025
a531b7d
ref: refactor ok or else
LeoPatOZ Oct 28, 2025
435dee3
fix: Retry updates (#141)
0xNeshi Oct 28, 2025
617629e
fix: rename error
LeoPatOZ Oct 28, 2025
f2b2281
feat: unwrap block in robust provider
LeoPatOZ Oct 28, 2025
4559c0a
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 28, 2025
34692bb
fix: merge errors
LeoPatOZ Oct 28, 2025
47b7aa5
fix: test post merge
LeoPatOZ Oct 28, 2025
ec32c31
Merge branch 'main' into retry-logic
LeoPatOZ Oct 28, 2025
c9f140d
fix: more merge errors
LeoPatOZ Oct 28, 2025
7923de1
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 28, 2025
8eff737
Update src/block_range_scanner.rs
LeoPatOZ Oct 28, 2025
b34dbbe
fix: brackets
LeoPatOZ Oct 28, 2025
82878f6
fix: only return true on reorg detected if err is block not found
LeoPatOZ Oct 28, 2025
318a810
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 28, 2025
7b8b082
ref: remove pubsub check
LeoPatOZ Oct 29, 2025
ac3d47f
Merge branch 'main' into retry-logic
LeoPatOZ Oct 29, 2025
63cefb9
feat: merge changes
LeoPatOZ Oct 29, 2025
03128b6
Merge branch 'retry-logic' into multiple-providers
LeoPatOZ Oct 29, 2025
5df42d3
chore: add back fallback provider to scanners
LeoPatOZ Oct 30, 2025
4a63f7e
feat: update block range scanner to use url for fallback
LeoPatOZ Oct 30, 2025
8e5a85e
feat: add errors back
LeoPatOZ Oct 30, 2025
63eb7d4
ref: remove generic network param from scanners
LeoPatOZ Oct 30, 2025
c7fdfbc
fix: update tests
LeoPatOZ Oct 30, 2025
6bab724
ref: remove generic Network param from builder
LeoPatOZ Oct 30, 2025
77eabd5
feat: add fallback provider logic to event scanners
LeoPatOZ Oct 30, 2025
82062f5
Merge branch 'main' into multiple-providers
LeoPatOZ Oct 30, 2025
01dfc74
fix: doctest
LeoPatOZ Oct 30, 2025
a1ad206
feat: remove all connect_x methods and pass provider in directly
LeoPatOZ Oct 30, 2025
c81ddb2
ref: remove connect_ methods and just connect directly
LeoPatOZ Oct 30, 2025
8030514
feat: add expect pubsub as rrobust provider doesnt distinguish provid…
LeoPatOZ Oct 30, 2025
dfa2840
fix: let anvil live long enough
LeoPatOZ Oct 30, 2025
9bf2b7e
ref: reorg provider logic
LeoPatOZ Oct 30, 2025
ee8512f
ref: remove comment about test module
LeoPatOZ Oct 30, 2025
1a5541f
ref: move assert reorg to top for easy debugging
LeoPatOZ Oct 30, 2025
a717ef4
ref: pass anvil by reference (prevents being dropped too early)
LeoPatOZ Oct 30, 2025
3c4ebb1
ref: only connect to robust provider
LeoPatOZ Oct 31, 2025
c89da66
test: fix reorg_rescans_events_within_same_block (#147)
0xNeshi Nov 3, 2025
64cdafb
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 3, 2025
0ebee92
fix: update ater merge
LeoPatOZ Nov 3, 2025
55223e8
ref: split common into differnet files
LeoPatOZ Nov 3, 2025
4fe722a
feat: add inner
LeoPatOZ Nov 3, 2025
0160914
ref: use inner
LeoPatOZ Nov 3, 2025
a0aa387
ref: use inner in latest_event
LeoPatOZ Nov 3, 2025
c9c7e2a
fix: broken block range scanner tests
LeoPatOZ Nov 3, 2025
acbe489
fix: reorg test
LeoPatOZ Nov 3, 2025
00894e3
ref: update reorg two test
LeoPatOZ Nov 3, 2025
2221c2f
ref: refactor all reorg tests
LeoPatOZ Nov 3, 2025
0587bbe
ref: remove complex reorg function
LeoPatOZ Nov 3, 2025
c171388
fix: doctest + readme
LeoPatOZ Nov 3, 2025
966e94a
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 3, 2025
ac024f5
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 4, 2025
4aa0759
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 4, 2025
e4e4618
fix: merge conflicts
LeoPatOZ Nov 4, 2025
e326645
ref: remove to_root()
LeoPatOZ Nov 4, 2025
808c611
ref: remove Etheruem generic
LeoPatOZ Nov 4, 2025
7cae13b
ref: remove is_err check
LeoPatOZ Nov 4, 2025
a616703
ref: change inner --> root
LeoPatOZ Nov 4, 2025
f3958af
feat: use providers vec to store all primary and fallback providers
LeoPatOZ Nov 4, 2025
8b1079c
feat: add retry notification
LeoPatOZ Nov 4, 2025
fcf7cd0
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 5, 2025
9d1df37
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 5, 2025
ef3b363
fix: test
LeoPatOZ Nov 5, 2025
e9900cf
fix: add back timeoute
LeoPatOZ Nov 5, 2025
809b657
feat: better error handling
LeoPatOZ Nov 5, 2025
e4d5d62
feat: remove retry erro
LeoPatOZ Nov 6, 2025
297fc35
feat: retry_interval to min delay
LeoPatOZ Nov 6, 2025
b93bd28
feat: rename retry interval in other places
LeoPatOZ Nov 6, 2025
635c02a
feat: doc comments
LeoPatOZ Nov 6, 2025
1a4905a
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 6, 2025
d1aaa04
fix: import and provider issues in test
LeoPatOZ Nov 6, 2025
3274332
fix: test
LeoPatOZ Nov 6, 2025
b620c3b
ref: revert changes to block range test
LeoPatOZ Nov 6, 2025
13d7529
ref: retry_with_total_timeout
LeoPatOZ Nov 6, 2025
956c77f
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 6, 2025
655124a
Pubsub checks (#153)
LeoPatOZ Nov 7, 2025
4873a13
ref: root --> primary provider
LeoPatOZ Nov 7, 2025
d50ec85
ref: dont panic on pubsub nt supported
LeoPatOZ Nov 7, 2025
532209e
ref: remove skipped count + return primary provider error
LeoPatOZ Nov 7, 2025
e0dbfa9
ref: take len out of loop
LeoPatOZ Nov 7, 2025
394fccf
ref: better logging
LeoPatOZ Nov 7, 2025
ba2275f
ref: remove async test
LeoPatOZ Nov 7, 2025
4f17184
doc: better error returned
LeoPatOZ Nov 7, 2025
58d6690
feat: provider better feature examples of robust provider in the exam…
LeoPatOZ Nov 7, 2025
87d6029
feat: change port
LeoPatOZ Nov 7, 2025
fbec4a8
ref: remove timeout
LeoPatOZ Nov 7, 2025
a24ba66
Merge branch 'main' into multiple-providers
LeoPatOZ Nov 7, 2025
16128db
feat: Support conversions (#164)
0xNeshi Nov 7, 2025
48d9863
feat: dont error out if PP doesn't support pubsub on subscription
0xNeshi Nov 7, 2025
f65ffaf
test: fix
0xNeshi Nov 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,24 @@ event-scanner = "0.4.0-alpha"
Create an event stream for the given event filters registered with the `EventScanner`:

```rust
use alloy::{network::Ethereum, sol_types::SolEvent};
use event_scanner::{EventFilter, EventScannerBuilder, Message};
use alloy::{network::Ethereum, providers::{Provider, ProviderBuilder}, sol_types::SolEvent};
use event_scanner::{EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder};
use tokio_stream::StreamExt;

use crate::MyContract;

async fn run_scanner(
ws_url: alloy::transports::http::reqwest::Url,
ws_url: &str,
contract: alloy::primitives::Address,
) -> Result<(), Box<dyn std::error::Error>> {
// Connect to provider
let provider = ProviderBuilder::new().connect(ws_url).await?;
let robust_provider = RobustProviderBuilder::new(provider).build().await?;

// Configure scanner with custom batch size (optional)
let mut scanner = EventScannerBuilder::live()
.max_block_range(500) // Process up to 500 blocks per batch
.connect_ws::<Ethereum>(ws_url).await?;
.connect(robust_provider);

// Register an event listener
let filter = EventFilter::new()
Expand Down Expand Up @@ -109,48 +113,56 @@ async fn run_scanner(

### Building a Scanner

`EventScannerBuilder` provides mode-specific constructors and a functions to configure settings before connecting.
Once configured, connect using one of:
`EventScannerBuilder` provides mode-specific constructors and functions to configure settings before connecting.
Once configured, connect using:

- `connect_ws::<Ethereum>(ws_url)`
- `connect_ipc::<Ethereum>(path)`
- `connect::<Ethereum>(provider)`
- `connect(provider)` - Connect using a `RobustProvider` wrapping your alloy provider or using an alloy provider directly

This will connect the `EventScanner` and allow you to create event streams and start scanning in various [modes](#scanning-modes).

```rust
use alloy::providers::{Provider, ProviderBuilder};
use event_scanner::robust_provider::RobustProviderBuilder;

// Connect to provider (example with WebSocket)
let provider = ProviderBuilder::new().connect("ws://localhost:8545").await?;

// Live streaming mode
let scanner = EventScannerBuilder::live()
.max_block_range(500) // Optional: set max blocks per read (default: 1000)
.block_confirmations(12) // Optional: set block confirmations (default: 12)
.connect_ws::<Ethereum>(ws_url).await?;
.connect(provider.clone());

// Historical block range mode
let scanner = EventScannerBuilder::historic()
.from_block(1_000_000)
.to_block(2_000_000)
.max_block_range(500)
.connect_ws::<Ethereum>(ws_url).await?;
.connect(provider.clone());

// we can also wrap the provider in a RobustProvider
// for more advanced configurations like retries and fallbacks
let robust_provider = RobustProviderBuilder::new(provider).build().await?;

// Latest events mode
let scanner = EventScannerBuilder::latest(100)
// .from_block(1_000_000) // Optional: set start of search range
// .to_block(2_000_000) // Optional: set end of search range
.max_block_range(500)
.connect_ws::<Ethereum>(ws_url).await?;
.connect(robust_provider.clone());

// Sync from block then switch to live mode
let scanner = EventScannerBuilder::sync()
.from_block(100)
.max_block_range(500)
.block_confirmations(12)
.connect_ws::<Ethereum>(ws_url).await?;
.connect(robust_provider.clone());

// Sync the latest 60 events then switch to live mode
let scanner = EventScannerBuilder::sync()
.from_latest(60)
.block_confirmations(12)
.connect_ws::<Ethereum>(ws_url).await?;
.connect(robust_provider);
```

Invoking `scanner.start()` starts the scanner in the specified mode.
Expand Down
24 changes: 17 additions & 7 deletions examples/historical_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use alloy::{network::Ethereum, providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy::{providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy_node_bindings::Anvil;

use event_scanner::{EventFilter, EventScannerBuilder, Message};
use event_scanner::{
EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder,
};
use tokio_stream::StreamExt;
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -38,9 +40,11 @@ async fn main() -> anyhow::Result<()> {

let anvil = Anvil::new().block_time_f64(0.1).try_spawn()?;
let wallet = anvil.wallet();
let provider =
ProviderBuilder::new().wallet(wallet.unwrap()).connect(anvil.endpoint().as_str()).await?;
let counter_contract = Counter::deploy(provider).await?;
let provider = ProviderBuilder::new()
.wallet(wallet.unwrap())
.connect(anvil.ws_endpoint_url().as_str())
.await?;
let counter_contract = Counter::deploy(provider.clone()).await?;

let contract_address = counter_contract.address();

Expand All @@ -50,8 +54,14 @@ async fn main() -> anyhow::Result<()> {

let _ = counter_contract.increase().send().await?.get_receipt().await?;

let mut scanner =
EventScannerBuilder::historic().connect_ws::<Ethereum>(anvil.ws_endpoint_url()).await?;
let robust_provider = RobustProviderBuilder::new(provider)
.max_timeout(std::time::Duration::from_secs(30))
.max_retries(5)
.min_delay(std::time::Duration::from_millis(500))
.build()
.await?;

let mut scanner = EventScannerBuilder::historic().connect(robust_provider).await?;

let mut stream = scanner.subscribe(increase_filter);

Expand Down
24 changes: 17 additions & 7 deletions examples/latest_events_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use alloy::{network::Ethereum, providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy::{providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy_node_bindings::Anvil;
use event_scanner::{EventFilter, EventScannerBuilder, Message};
use event_scanner::{
EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder,
};
use tokio_stream::StreamExt;
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -37,18 +39,26 @@ async fn main() -> anyhow::Result<()> {

let anvil = Anvil::new().block_time_f64(0.5).try_spawn()?;
let wallet = anvil.wallet();
let provider =
ProviderBuilder::new().wallet(wallet.unwrap()).connect(anvil.endpoint().as_str()).await?;
let counter_contract = Counter::deploy(provider).await?;
let provider = ProviderBuilder::new()
.wallet(wallet.unwrap())
.connect(anvil.ws_endpoint_url().as_str())
.await?;
let counter_contract = Counter::deploy(provider.clone()).await?;

let contract_address = counter_contract.address();

let increase_filter = EventFilter::new()
.contract_address(*contract_address)
.event(Counter::CountIncreased::SIGNATURE);

let mut scanner =
EventScannerBuilder::latest(5).connect_ws::<Ethereum>(anvil.ws_endpoint_url()).await?;
let robust_provider = RobustProviderBuilder::new(provider)
.max_timeout(std::time::Duration::from_secs(30))
.max_retries(5)
.min_delay(std::time::Duration::from_millis(500))
.build()
.await?;

let mut scanner = EventScannerBuilder::latest(5).connect(robust_provider).await?;

let mut stream = scanner.subscribe(increase_filter);

Expand Down
24 changes: 17 additions & 7 deletions examples/live_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use alloy::{network::Ethereum, providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy::{providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy_node_bindings::Anvil;
use event_scanner::{EventFilter, EventScannerBuilder, Message};
use event_scanner::{
EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder,
};

use tokio_stream::StreamExt;
use tracing::{error, info};
Expand Down Expand Up @@ -38,18 +40,26 @@ async fn main() -> anyhow::Result<()> {

let anvil = Anvil::new().block_time(1).try_spawn()?;
let wallet = anvil.wallet();
let provider =
ProviderBuilder::new().wallet(wallet.unwrap()).connect(anvil.endpoint().as_str()).await?;
let counter_contract = Counter::deploy(provider).await?;
let provider = ProviderBuilder::new()
.wallet(wallet.unwrap())
.connect(anvil.ws_endpoint_url().as_str())
.await?;
let counter_contract = Counter::deploy(provider.clone()).await?;

let contract_address = counter_contract.address();

let increase_filter = EventFilter::new()
.contract_address(*contract_address)
.event(Counter::CountIncreased::SIGNATURE);

let mut scanner =
EventScannerBuilder::live().connect_ws::<Ethereum>(anvil.ws_endpoint_url()).await?;
let robust_provider = RobustProviderBuilder::new(provider)
.max_timeout(std::time::Duration::from_secs(30))
.max_retries(5)
.min_delay(std::time::Duration::from_millis(500))
.build()
.await?;

let mut scanner = EventScannerBuilder::live().connect(robust_provider).await?;

let mut stream = scanner.subscribe(increase_filter);

Expand Down
24 changes: 16 additions & 8 deletions examples/sync_from_block_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::time::Duration;

use alloy::{network::Ethereum, providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy::{providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy_node_bindings::Anvil;
use event_scanner::{EventFilter, EventScannerBuilder, Message};
use event_scanner::{
EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder,
};
use tokio::time::sleep;
use tokio_stream::StreamExt;
use tracing::{error, info};
Expand Down Expand Up @@ -40,9 +42,11 @@ async fn main() -> anyhow::Result<()> {

let anvil = Anvil::new().block_time(1).try_spawn()?;
let wallet = anvil.wallet();
let provider =
ProviderBuilder::new().wallet(wallet.unwrap()).connect(anvil.endpoint().as_str()).await?;
let counter_contract = Counter::deploy(provider).await?;
let provider = ProviderBuilder::new()
.wallet(wallet.unwrap())
.connect(anvil.ws_endpoint_url().as_str())
.await?;
let counter_contract = Counter::deploy(provider.clone()).await?;

let contract_address = counter_contract.address();

Expand All @@ -56,11 +60,15 @@ async fn main() -> anyhow::Result<()> {
info!("Historical event {} created", i + 1);
}

let mut scanner = EventScannerBuilder::sync()
.from_block(0)
.connect_ws::<Ethereum>(anvil.ws_endpoint_url())
let robust_provider = RobustProviderBuilder::new(provider)
.max_timeout(Duration::from_secs(30))
.max_retries(5)
.min_delay(Duration::from_millis(500))
.build()
.await?;

let mut scanner = EventScannerBuilder::sync().from_block(0).connect(robust_provider).await?;

let mut stream = scanner.subscribe(increase_filter);

info!("Starting sync scanner...");
Expand Down
24 changes: 16 additions & 8 deletions examples/sync_from_latest_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use alloy::{network::Ethereum, providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy::{providers::ProviderBuilder, sol, sol_types::SolEvent};
use alloy_node_bindings::Anvil;
use event_scanner::{EventFilter, EventScannerBuilder, Message};
use event_scanner::{
EventFilter, EventScannerBuilder, Message, robust_provider::RobustProviderBuilder,
};

use tokio_stream::StreamExt;
use tracing::{error, info};
Expand Down Expand Up @@ -38,21 +40,27 @@ async fn main() -> anyhow::Result<()> {

let anvil = Anvil::new().block_time_f64(0.5).try_spawn()?;
let wallet = anvil.wallet();
let provider =
ProviderBuilder::new().wallet(wallet.unwrap()).connect(anvil.endpoint().as_str()).await?;
let counter_contract = Counter::deploy(provider).await?;
let provider = ProviderBuilder::new()
.wallet(wallet.unwrap())
.connect(anvil.ws_endpoint_url().as_str())
.await?;
let counter_contract = Counter::deploy(provider.clone()).await?;

let contract_address = counter_contract.address();

let increase_filter = EventFilter::new()
.contract_address(*contract_address)
.event(Counter::CountIncreased::SIGNATURE);

let mut client = EventScannerBuilder::sync()
.from_latest(5)
.connect_ws::<Ethereum>(anvil.ws_endpoint_url())
let robust_provider = RobustProviderBuilder::new(provider)
.max_timeout(std::time::Duration::from_secs(30))
.max_retries(5)
.min_delay(std::time::Duration::from_millis(500))
.build()
.await?;

let mut client = EventScannerBuilder::sync().from_latest(5).connect(robust_provider).await?;

let mut stream = client.subscribe(increase_filter);

for _ in 0..10 {
Expand Down
Loading
Loading