update jsonrpsee

This commit is contained in:
Niklas
2021-12-21 11:06:59 +01:00
parent 8e6b277e34
commit 752c19e2f4
4 changed files with 18 additions and 29 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ chameleon = "0.1.0"
scale-info = { version = "1.0.0", features = ["bit-vec"] } scale-info = { version = "1.0.0", features = ["bit-vec"] }
futures = "0.3.13" futures = "0.3.13"
hex = "0.4.3" 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" log = "0.4.14"
num-traits = { version = "0.2.14", default-features = false } num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0.124", features = ["derive"] } serde = { version = "1.0.124", features = ["derive"] }
+2 -2
View File
@@ -22,7 +22,7 @@ use crate::{
}, },
Metadata, Metadata,
}; };
use jsonrpsee::types::Error as RequestError; use jsonrpsee::core::Error as RpcError;
use sp_core::crypto::SecretStringError; use sp_core::crypto::SecretStringError;
use sp_runtime::{ use sp_runtime::{
transaction_validity::TransactionValidityError, transaction_validity::TransactionValidityError,
@@ -41,7 +41,7 @@ pub enum Error {
Codec(#[from] codec::Error), Codec(#[from] codec::Error),
/// Rpc error. /// Rpc error.
#[error("Rpc error: {0}")] #[error("Rpc error: {0}")]
Rpc(#[from] RequestError), Rpc(#[from] RpcError),
/// Serde serialization error /// Serde serialization error
#[error("Serde json error: {0}")] #[error("Serde json error: {0}")]
Serialization(#[from] serde_json::error::Error), Serialization(#[from] serde_json::error::Error),
+11 -19
View File
@@ -41,22 +41,20 @@ pub use jsonrpsee::{
Uri, Uri,
WsTransportClientBuilder, WsTransportClientBuilder,
}, },
core_client::{ core::{
Client as RpcClient, client::{
ClientBuilder as RpcClientBuilder, Client as RpcClient,
}, ClientBuilder as RpcClientBuilder,
rpc_params, ClientT,
types::{ Subscription,
to_json_value, SubscriptionClientT,
traits::{
Client,
SubscriptionClient,
}, },
to_json_value,
DeserializeOwned, DeserializeOwned,
Error as RpcError, Error as RpcError,
JsonValue, JsonValue,
Subscription,
}, },
rpc_params,
}; };
use serde::{ use serde::{
Deserialize, Deserialize,
@@ -488,10 +486,10 @@ impl<T: Config> Rpc<T> {
}?; }?;
let mut xt_sub = self.watch_extrinsic(extrinsic).await?; 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); log::info!("Received status {:?}", status);
let status = status?;
match status { match status {
// ignore in progress extrinsic for now
TransactionStatus::Future TransactionStatus::Future
| TransactionStatus::Ready | TransactionStatus::Ready
| TransactionStatus::Broadcast(_) | TransactionStatus::Broadcast(_)
@@ -640,12 +638,6 @@ impl<T: Config> ExtrinsicSuccess<T> {
} }
} }
/// Example to check that `From<(Sender, Receiver) for RpcClient` works.
pub async fn build_ws_client_default(url: &str) -> Result<RpcClient, RpcError> {
let client = ws_transport(url).await?.into();
Ok(client)
}
/// Build WS RPC client from URL /// Build WS RPC client from URL
pub async fn build_ws_client(url: &str) -> Result<RpcClient, RpcError> { pub async fn build_ws_client(url: &str) -> Result<RpcClient, RpcError> {
let (sender, receiver) = ws_transport(url).await?; let (sender, receiver) = ws_transport(url).await?;
+4 -7
View File
@@ -14,10 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>. // along with subxt. If not, see <http://www.gnu.org/licenses/>.
use jsonrpsee::types::{ use jsonrpsee::core::{DeserializeOwned, client::Subscription};
DeserializeOwned,
Subscription,
};
use sp_core::{ use sp_core::{
storage::{ storage::{
StorageChangeSet, StorageChangeSet,
@@ -253,9 +250,9 @@ where
T: DeserializeOwned, T: DeserializeOwned,
{ {
match sub.next().await { match sub.next().await {
Ok(Some(next)) => Some(next), None => None,
Ok(None) => None, Some(Ok(next)) => Some(next),
Err(e) => { Some(Err(e)) => {
log::error!("Subscription {} failed: {:?} dropping", sub_name, e); log::error!("Subscription {} failed: {:?} dropping", sub_name, e);
None None
} }