mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 14:01:06 +00:00
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:
@@ -19,9 +19,13 @@ use std::collections::VecDeque;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use crate::backend::unstable::UnstableBlockRef;
|
||||
|
||||
// Expose the RPC methods.
|
||||
pub use rpc_methods::LegacyRpcMethods;
|
||||
|
||||
use super::unstable::rpc_methods::FollowEvent;
|
||||
|
||||
/// The legacy backend.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LegacyBackend<T> {
|
||||
@@ -41,6 +45,13 @@ impl<T: Config> super::sealed::Sealed for LegacyBackend<T> {}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Config + Send + Sync + 'static> Backend<T> for LegacyBackend<T> {
|
||||
/// ChainHead follow
|
||||
async fn chain_head_follow(
|
||||
&self,
|
||||
) -> Result<StreamOfResults<FollowEvent<UnstableBlockRef<T::Hash>>>, Error> {
|
||||
panic!("Unimplemented")
|
||||
}
|
||||
|
||||
async fn storage_fetch_values(
|
||||
&self,
|
||||
keys: Vec<Vec<u8>>,
|
||||
|
||||
@@ -19,6 +19,10 @@ use futures::{Stream, StreamExt};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::backend::unstable::UnstableBlockRef;
|
||||
|
||||
use self::unstable::rpc_methods::FollowEvent;
|
||||
|
||||
/// Prevent the backend trait being implemented externally.
|
||||
#[doc(hidden)]
|
||||
pub(crate) mod sealed {
|
||||
@@ -99,6 +103,11 @@ pub trait Backend<T: Config>: sealed::Sealed + Send + Sync + 'static {
|
||||
call_parameters: Option<&[u8]>,
|
||||
at: T::Hash,
|
||||
) -> Result<Vec<u8>, Error>;
|
||||
|
||||
/// ChainHead follow
|
||||
async fn chain_head_follow(
|
||||
&self,
|
||||
) -> Result<StreamOfResults<FollowEvent<UnstableBlockRef<T::Hash>>>, Error>;
|
||||
}
|
||||
|
||||
/// helpeful utility methods derived from those provided on [`Backend`]
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user