Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider): return Subscription<N::HeaderResponse> #1586

Merged
merged 3 commits into from
Oct 30, 2024
Merged
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
18 changes: 8 additions & 10 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
#[cfg(feature = "pubsub")]
async fn subscribe_blocks(
&self,
) -> TransportResult<alloy_pubsub::Subscription<N::BlockResponse>> {
) -> TransportResult<alloy_pubsub::Subscription<N::HeaderResponse>> {
self.root().pubsub_frontend()?;
let id = self.client().request("eth_subscribe", ("newHeads",)).await?;
self.root().get_subscription(id).await
Expand Down Expand Up @@ -1351,9 +1351,8 @@ mod tests {
let sub = provider.subscribe_blocks().await.unwrap();
let mut stream = sub.into_stream().take(2);
let mut n = 1;
while let Some(block) = stream.next().await {
assert_eq!(block.header.number, n);
assert_eq!(block.transactions.hashes().len(), 0);
while let Some(header) = stream.next().await {
assert_eq!(header.number, n);
n += 1;
}
}
Expand All @@ -1372,9 +1371,8 @@ mod tests {
let sub = provider.subscribe_blocks().await.unwrap();
let mut stream = sub.into_stream().take(2);
let mut n = 1;
while let Some(block) = stream.next().await {
assert_eq!(block.header.number, n);
assert_eq!(block.transactions.hashes().len(), 0);
while let Some(header) = stream.next().await {
assert_eq!(header.number, n);
n += 1;
}
}
Expand All @@ -1390,9 +1388,9 @@ mod tests {
let provider = RootProvider::<_, Ethereum>::new(client);
let sub = provider.subscribe_blocks().await.unwrap();
let mut stream = sub.into_stream().take(1);
while let Some(block) = stream.next().await {
println!("New block {:?}", block);
assert!(block.header.number > 0);
while let Some(header) = stream.next().await {
println!("New block {:?}", header);
assert!(header.number > 0);
}
}

Expand Down