subxt: Expose chainHeadFollow on the backend and test order of blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2024-01-09 18:27:28 +02:00
parent 32b7d46135
commit 9a587b360d
4 changed files with 128 additions and 13 deletions
+15
View File
@@ -16,6 +16,8 @@ mod follow_stream_driver;
mod follow_stream_unpin;
mod storage_items;
pub use follow_stream_unpin::BlockRef as UnstableBlockRef;
pub mod rpc_methods;
use self::rpc_methods::{
@@ -25,6 +27,7 @@ use crate::backend::{
rpc::RpcClient, Backend, BlockRef, BlockRefT, RuntimeVersion, StorageResponse, StreamOf,
StreamOfResults, TransactionStatus,
};
use crate::config::BlockHash;
use crate::error::{Error, RpcError};
use crate::Config;
@@ -332,6 +335,18 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
next_ref.ok_or_else(|| RpcError::SubscriptionDropped.into())
}
async fn chain_head_follow(
&self,
) -> Result<StreamOfResults<FollowEvent<UnstableBlockRef<T::Hash>>>, Error> {
let stream = self
.follow_handle
.subscribe()
.events()
.map(|event| Ok(event));
Ok(StreamOf(Box::pin(stream)))
}
async fn current_runtime_version(&self) -> Result<RuntimeVersion, Error> {
// Just start a stream of version infos, and return the first value we get from it.
let runtime_version = self.stream_runtime_version().await?.next().await;