pub struct EventsMethods { /* private fields */ }Expand description
Methods for fetching Circles events over HTTP or websocket.
WS helpers subscribe to eth_subscribe("circles", filter), drop heartbeat
frames ([]), flatten batches, and parse into CirclesEvent when desired.
Implementations§
Source§impl EventsMethods
impl EventsMethods
Sourcepub async fn circles_events(
&self,
address: Option<Address>,
from_block: u64,
to_block: Option<u64>,
filter: Option<Vec<Filter>>,
) -> Result<Vec<CirclesEvent>>
pub async fn circles_events( &self, address: Option<Address>, from_block: u64, to_block: Option<u64>, filter: Option<Vec<Filter>>, ) -> Result<Vec<CirclesEvent>>
HTTP: circles_events(address, fromBlock, toBlock?, filter?)
Sourcepub async fn subscribe_circles_events<F>(
&self,
filter: F,
) -> Result<CirclesSubscription<RpcSubscriptionEvent>>where
F: RpcSend + 'static,
pub async fn subscribe_circles_events<F>(
&self,
filter: F,
) -> Result<CirclesSubscription<RpcSubscriptionEvent>>where
F: RpcSend + 'static,
Subscribe via eth_subscribe("circles", filter) and yield raw RpcSubscriptionEvents.
Sourcepub async fn subscribe_parsed_events<F>(
&self,
filter: F,
) -> Result<CirclesSubscription<CirclesEvent>>where
F: RpcSend + 'static,
pub async fn subscribe_parsed_events<F>(
&self,
filter: F,
) -> Result<CirclesSubscription<CirclesEvent>>where
F: RpcSend + 'static,
Subscribe and parse into CirclesEvent using the canonical parser.
Examples found in repository?
examples/paged_and_ws.rs (line 85)
78async fn stream_events(rpc: &CirclesRpc, address: Address) -> Result<()> {
79 use tokio::time::timeout;
80
81 println!("Subscribing to Circles events for address {address}");
82 // Empty filter = firehose; add {"address": <addr>} to narrow. Some public WS
83 // endpoints currently emit empty [] heartbeats and no payloads.
84 let filter = serde_json::json!({});
85 let mut sub = match rpc.events().subscribe_parsed_events(filter).await {
86 Ok(sub) => sub,
87 Err(e) => {
88 eprintln!("subscription failed: {e}");
89 return Ok(());
90 }
91 };
92
93 let mut seen = 0u32;
94 loop {
95 match timeout(Duration::from_secs(15), sub.next()).await {
96 Ok(Some(Ok(evt))) => {
97 println!(
98 "event: {:?} @ block {}",
99 evt.event_type, evt.base.block_number
100 );
101 seen += 1;
102 if seen >= 3 {
103 break;
104 }
105 }
106 Ok(Some(Err(e))) => {
107 println!("event stream error: {e}");
108 break;
109 }
110 Ok(None) => {
111 println!("subscription closed");
112 break;
113 }
114 Err(_) => {
115 println!("no events within timeout, stopping");
116 break;
117 }
118 }
119 }
120
121 println!("Unsubscribing after {seen} events");
122 // Drop will best-effort eth_unsubscribe, but explicit is fine too.
123 let _ = sub.unsubscribe();
124
125 // Debug helper: also try a raw Value subscription to inspect payloads when parsing fails.
126 debug_raw_ws(address).await;
127 Ok(())
128}Trait Implementations§
Source§impl Clone for EventsMethods
impl Clone for EventsMethods
Source§fn clone(&self) -> EventsMethods
fn clone(&self) -> EventsMethods
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for EventsMethods
impl !RefUnwindSafe for EventsMethods
impl Send for EventsMethods
impl Sync for EventsMethods
impl Unpin for EventsMethods
impl UnsafeUnpin for EventsMethods
impl !UnwindSafe for EventsMethods
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more