1use futures::StreamExt;
2use subxt::{OnlineClient, SubstrateConfig};
3use anyhow::Result;
4
5pub struct EventManager;
6
7impl EventManager {
8 pub async fn subscribe_blocks(api: &OnlineClient<SubstrateConfig>, limit: Option<usize>) -> Result<()> {
9 let mut blocks_sub = api.blocks().subscribe_finalized().await?;
10 let mut count = 0;
11
12 while let Some(block) = blocks_sub.next().await {
13 let block = block?;
14 println!("📦 Finalized block: #{} ({})", block.number(), block.hash());
15 count += 1;
16 if let Some(l) = limit {
17 if count >= l { break; }
18 }
19 }
20
21 Ok(())
22 }
23}