mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Switch the client to new futures (#3103)
* Switch the client to new futures * No need for compat in the client * Fix client tests * Address review
This commit is contained in:
committed by
Bastian Köcher
parent
f5e921281e
commit
bf2551a854
@@ -7,6 +7,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
derive_more = "0.14.0"
|
||||
futures = "0.1"
|
||||
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
|
||||
jsonrpc-core = "12.0.0"
|
||||
jsonrpc-core-client = "12.0.0"
|
||||
jsonrpc-pubsub = "12.0.0"
|
||||
|
||||
@@ -23,6 +23,7 @@ pub mod number;
|
||||
mod tests;
|
||||
|
||||
use std::sync::Arc;
|
||||
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
||||
|
||||
use client::{self, Client, BlockchainEvents};
|
||||
use crate::rpc::Result as RpcResult;
|
||||
@@ -203,8 +204,9 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
|
||||
subscriber,
|
||||
|| self.block_hash(None.into()),
|
||||
|| self.client.import_notification_stream()
|
||||
.filter(|notification| notification.is_new_best)
|
||||
.map(|notification| notification.header),
|
||||
.filter(|notification| future::ready(notification.is_new_best))
|
||||
.map(|notification| Ok::<_, ()>(notification.header))
|
||||
.compat(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -217,7 +219,8 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
|
||||
subscriber,
|
||||
|| Ok(Some(self.client.info().chain.finalized_hash)),
|
||||
|| self.client.finality_notification_stream()
|
||||
.map(|notification| notification.header),
|
||||
.map(|notification| Ok::<_, ()>(notification.header))
|
||||
.compat(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ use std::{
|
||||
ops::Range,
|
||||
sync::Arc,
|
||||
};
|
||||
use futures03::{future, StreamExt as _, TryStreamExt as _};
|
||||
|
||||
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
||||
use crate::rpc::Result as RpcResult;
|
||||
@@ -484,14 +485,14 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
|
||||
self.subscriptions.add(subscriber, |sink| {
|
||||
let stream = stream
|
||||
.map_err(|e| warn!("Error creating storage notification stream: {:?}", e))
|
||||
.map(|(block, changes)| Ok(StorageChangeSet {
|
||||
.map(|(block, changes)| Ok::<_, ()>(Ok(StorageChangeSet {
|
||||
block,
|
||||
changes: changes.iter()
|
||||
.filter_map(|(o_sk, k, v)| if o_sk.is_none() {
|
||||
Some((k.clone(),v.cloned()))
|
||||
} else { None }).collect(),
|
||||
}));
|
||||
})))
|
||||
.compat();
|
||||
|
||||
sink
|
||||
.sink_map_err(|e| warn!("Error sending notifications: {:?}", e))
|
||||
@@ -530,7 +531,6 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
let mut previous_version = version.clone();
|
||||
|
||||
let stream = stream
|
||||
.map_err(|e| warn!("Error creating storage notification stream: {:?}", e))
|
||||
.filter_map(move |_| {
|
||||
let info = client.info();
|
||||
let version = client
|
||||
@@ -539,11 +539,12 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
.map_err(Into::into);
|
||||
if previous_version != version {
|
||||
previous_version = version.clone();
|
||||
Some(version)
|
||||
future::ready(Some(Ok::<_, ()>(version)))
|
||||
} else {
|
||||
None
|
||||
future::ready(None)
|
||||
}
|
||||
});
|
||||
})
|
||||
.compat();
|
||||
|
||||
sink
|
||||
.sink_map_err(|e| warn!("Error sending notifications: {:?}", e))
|
||||
|
||||
Reference in New Issue
Block a user