use crate::{Api, Error, GearConfig, Result};
use futures::prelude::*;
use std::pin::pin;
pub type Block = subxt::blocks::Block<GearConfig, subxt::OnlineClient<GearConfig>>;
pub type Events = subxt::events::Events<GearConfig>;
pub async fn are_progressing<E>(blocks: impl Stream<Item = Result<Block, E>>) -> Result<bool>
where
Error: From<E>,
{
let mut blocks = pin!(blocks);
let current_block = blocks
.next()
.await
.transpose()?
.ok_or(Error::SubscriptionDied)?;
let next_block = blocks
.next()
.await
.transpose()?
.ok_or(Error::SubscriptionDied)?;
Ok(current_block.number() != next_block.number())
}
impl Api {
pub async fn is_progressing(&self) -> Result<bool> {
let blocks = self.blocks().subscribe_all().await?;
are_progressing(blocks).await
}
}