Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/examples/**/target
.DS_Store
.vscode
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[workspace]
members = [
".",
"examples/historical_scanning",
"examples/simple_counter",
]
members = [".", "examples/historical_scanning", "examples/simple_counter"]
resolver = "2"

[lints.clippy]
Expand Down
20 changes: 11 additions & 9 deletions examples/historical_scanning/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::{sync::Arc, time::Duration};

use alloy::{providers::ProviderBuilder, rpc::types::Log, sol, sol_types::SolEvent};
use alloy::{
eips::BlockNumberOrTag, network::Ethereum, providers::ProviderBuilder, rpc::types::Log, sol,
sol_types::SolEvent,
};
use alloy_node_bindings::Anvil;
use async_trait::async_trait;
use event_scanner::{EventCallback, EventFilter, FixedRetryConfig, ScannerBuilder};
use event_scanner::{EventCallback, EventFilter, event_scanner::EventScannerBuilder};

use tokio::time::sleep;
use tracing::info;
Expand Down Expand Up @@ -64,15 +67,14 @@ async fn main() -> anyhow::Result<()> {

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

let mut scanner = ScannerBuilder::new(anvil.ws_endpoint_url())
.add_event_filter(increase_filter)
.callback_config(FixedRetryConfig { max_attempts: 3, delay_ms: 200 })
.start_block(0)
.build()
.await?;
let mut builder = EventScannerBuilder::new();

builder.with_event_filter(increase_filter);

let mut scanner = builder.connect_ws::<Ethereum>(anvil.ws_endpoint_url()).await?;

sleep(Duration::from_secs(10)).await;
scanner.start().await.expect("failed to start scanner");
scanner.start(BlockNumberOrTag::Number(0), None).await.expect("failed to start scanner");

Ok(())
}
20 changes: 12 additions & 8 deletions examples/simple_counter/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::{sync::Arc, time::Duration};

use alloy::{providers::ProviderBuilder, rpc::types::Log, sol, sol_types::SolEvent};
use alloy::{
eips::BlockNumberOrTag, network::Ethereum, providers::ProviderBuilder, rpc::types::Log, sol,
sol_types::SolEvent,
};
use alloy_node_bindings::Anvil;
use async_trait::async_trait;
use event_scanner::{EventCallback, EventFilter, FixedRetryConfig, ScannerBuilder};
use event_scanner::{EventCallback, EventFilter, event_scanner::EventScannerBuilder};

use tokio::time::sleep;
use tracing::info;
Expand Down Expand Up @@ -62,14 +65,15 @@ async fn main() -> anyhow::Result<()> {
callback: Arc::new(CounterCallback),
};

let mut scanner = ScannerBuilder::new(anvil.ws_endpoint_url())
.add_event_filter(increase_filter)
.callback_config(FixedRetryConfig { max_attempts: 3, delay_ms: 200 })
.build()
.await?;
let mut builder = EventScannerBuilder::new();

builder.with_event_filter(increase_filter);

let scanner = builder.connect_ws::<Ethereum>(anvil.ws_endpoint_url()).await?;

let task_1 = tokio::spawn(async move {
scanner.start().await.expect("failed to start scanner");
let mut scanner = scanner;
scanner.start(BlockNumberOrTag::Latest, None).await.expect("failed to start scanner");
});

let task_2 = tokio::spawn(async move {
Expand Down
Loading