From 752c19e2f41e7b6602db0a84b03f2c34350e2c4c Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 21 Dec 2021 11:06:59 +0100 Subject: [PATCH] update jsonrpsee --- Cargo.toml | 2 +- src/error.rs | 4 ++-- src/rpc.rs | 30 +++++++++++------------------- src/subscription.rs | 11 ++++------- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6422d7da64..fa410e73b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ chameleon = "0.1.0" scale-info = { version = "1.0.0", features = ["bit-vec"] } futures = "0.3.13" hex = "0.4.3" -jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "extract-async-client", features = ["macros", "client"] } +jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "master", features = ["macros", "core-client", "client", "client-ws-transport"] } log = "0.4.14" num-traits = { version = "0.2.14", default-features = false } serde = { version = "1.0.124", features = ["derive"] } diff --git a/src/error.rs b/src/error.rs index f050b465a0..6067ac1558 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,7 @@ use crate::{ }, Metadata, }; -use jsonrpsee::types::Error as RequestError; +use jsonrpsee::core::Error as RpcError; use sp_core::crypto::SecretStringError; use sp_runtime::{ transaction_validity::TransactionValidityError, @@ -41,7 +41,7 @@ pub enum Error { Codec(#[from] codec::Error), /// Rpc error. #[error("Rpc error: {0}")] - Rpc(#[from] RequestError), + Rpc(#[from] RpcError), /// Serde serialization error #[error("Serde json error: {0}")] Serialization(#[from] serde_json::error::Error), diff --git a/src/rpc.rs b/src/rpc.rs index 8ef5a2a6cd..1fb3fa24d8 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -41,22 +41,20 @@ pub use jsonrpsee::{ Uri, WsTransportClientBuilder, }, - core_client::{ - Client as RpcClient, - ClientBuilder as RpcClientBuilder, - }, - rpc_params, - types::{ - to_json_value, - traits::{ - Client, - SubscriptionClient, + core::{ + client::{ + Client as RpcClient, + ClientBuilder as RpcClientBuilder, + ClientT, + Subscription, + SubscriptionClientT, }, + to_json_value, DeserializeOwned, Error as RpcError, JsonValue, - Subscription, }, + rpc_params, }; use serde::{ Deserialize, @@ -488,10 +486,10 @@ impl Rpc { }?; let mut xt_sub = self.watch_extrinsic(extrinsic).await?; - while let Ok(Some(status)) = xt_sub.next().await { + while let Some(status) = xt_sub.next().await { log::info!("Received status {:?}", status); + let status = status?; match status { - // ignore in progress extrinsic for now TransactionStatus::Future | TransactionStatus::Ready | TransactionStatus::Broadcast(_) @@ -640,12 +638,6 @@ impl ExtrinsicSuccess { } } -/// Example to check that `From<(Sender, Receiver) for RpcClient` works. -pub async fn build_ws_client_default(url: &str) -> Result { - let client = ws_transport(url).await?.into(); - Ok(client) -} - /// Build WS RPC client from URL pub async fn build_ws_client(url: &str) -> Result { let (sender, receiver) = ws_transport(url).await?; diff --git a/src/subscription.rs b/src/subscription.rs index c35771c27b..02ed9fa562 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with subxt. If not, see . -use jsonrpsee::types::{ - DeserializeOwned, - Subscription, -}; +use jsonrpsee::core::{DeserializeOwned, client::Subscription}; use sp_core::{ storage::{ StorageChangeSet, @@ -253,9 +250,9 @@ where T: DeserializeOwned, { match sub.next().await { - Ok(Some(next)) => Some(next), - Ok(None) => None, - Err(e) => { + None => None, + Some(Ok(next)) => Some(next), + Some(Err(e)) => { log::error!("Subscription {} failed: {:?} dropping", sub_name, e); None }