deps: update jsonrpsee 0.2.0 (#285)

* deps: update jsonrpsee 0.2.0

The motivation is to avoid pinning certain alpha versions and to avoid
breaking users builds without having to some `Cargo.lock` updating.

* cargo fmt

* fix tests

* fix a few clippy lints

* cargo fmt
This commit is contained in:
Niklas Adolfsson
2021-06-08 19:15:12 +02:00
committed by GitHub
parent 490836fa2d
commit 08a3e6574d
7 changed files with 73 additions and 50 deletions
+1 -1
View File
@@ -210,7 +210,7 @@ impl<T: Runtime> ClientBuilder<T> {
if url.starts_with("ws://") || url.starts_with("wss://") {
let client = WsClientBuilder::default()
.max_notifs_per_subscription(4096)
.build(&url)
.build(url)
.await?;
RpcClient::WebSocket(Arc::new(client))
} else {
+9 -9
View File
@@ -31,19 +31,19 @@ use core::{
marker::PhantomData,
};
use frame_metadata::RuntimeMetadataPrefixed;
use jsonrpsee_http_client::{
use jsonrpsee_http_client::HttpClient;
use jsonrpsee_types::{
to_json_value,
traits::Client,
traits::{
Client,
SubscriptionClient,
},
DeserializeOwned,
Error as RpcError,
HttpClient,
JsonValue,
};
use jsonrpsee_ws_client::{
traits::SubscriptionClient,
Subscription,
WsClient,
};
use jsonrpsee_ws_client::WsClient;
use serde::{
Deserialize,
Serialize,
@@ -541,7 +541,7 @@ impl<T: Runtime> Rpc<T> {
}?;
let mut xt_sub = self.watch_extrinsic(extrinsic).await?;
while let Some(status) = xt_sub.next().await {
while let Ok(Some(status)) = xt_sub.next().await {
log::info!("received status {:?}", status);
match status {
// ignore in progress extrinsic for now
@@ -604,7 +604,7 @@ impl<T: Runtime> Rpc<T> {
ext_hash,
))
})?;
let mut sub = EventSubscription::new(events_sub, &decoder);
let mut sub = EventSubscription::new(events_sub, decoder);
sub.filter_extrinsic(block_hash, ext_index);
let mut events = vec![];
while let Some(event) = sub.next().await {
+28 -3
View File
@@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use jsonrpsee_ws_client::Subscription;
use jsonrpsee_types::{
DeserializeOwned,
Subscription,
};
use sp_core::{
storage::{
StorageChangeSet,
@@ -176,7 +179,9 @@ impl<T: Runtime> FinalizedEventStorageSubscription<T> {
if let Some(storage_change) = self.storage_changes.pop_front() {
return Some(storage_change)
}
let header: T::Header = self.subscription.next().await?;
let header: T::Header =
read_subscription_response("HeaderSubscription", &mut self.subscription)
.await?;
self.storage_changes.extend(
self.rpc
.query_storage_at(&[self.storage_key.clone()], Some(header.hash()))
@@ -199,8 +204,28 @@ impl<T: Runtime> EventStorageSubscription<T> {
/// Gets the next change_set from the subscription.
pub async fn next(&mut self) -> Option<StorageChangeSet<T::Hash>> {
match self {
Self::Imported(event_sub) => event_sub.next().await,
Self::Imported(event_sub) => {
read_subscription_response("StorageChangeSetSubscription", event_sub)
.await
}
Self::Finalized(event_sub) => event_sub.next().await,
}
}
}
async fn read_subscription_response<T>(
sub_name: &str,
sub: &mut Subscription<T>,
) -> Option<T>
where
T: DeserializeOwned,
{
match sub.next().await {
Ok(Some(next)) => Some(next),
Ok(None) => None,
Err(e) => {
log::error!("Subscription {} failed: {:?} dropping", sub_name, e);
None
}
}
}
+2 -2
View File
@@ -141,7 +141,7 @@ async fn test_chain_subscribe_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.subscribe_blocks().await.unwrap();
blocks.next().await;
blocks.next().await.unwrap();
}
#[async_std::test]
@@ -149,7 +149,7 @@ async fn test_chain_subscribe_finalized_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.subscribe_finalized_blocks().await.unwrap();
blocks.next().await;
blocks.next().await.unwrap();
}
#[async_std::test]