From 1cd4f07b94e28a0a21b0e6d6ea6121af440a8cc8 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 14 Aug 2023 10:34:13 +0200 Subject: [PATCH 1/3] refactor: support default port in URL Update jsonrpsee to v0.20 to support the default port number in URLs. --- Cargo.lock | 132 +++++++++++----------------- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- cli/src/commands/compatibility.rs | 14 +-- cli/src/utils.rs | 12 +-- codegen/Cargo.toml | 2 +- codegen/src/api/mod.rs | 10 +-- codegen/src/utils/fetch_metadata.rs | 31 +++---- codegen/src/utils/mod.rs | 2 +- macro/src/lib.rs | 8 +- subxt/Cargo.toml | 4 +- subxt/src/client/online_client.rs | 12 ++- testing/test-runtime/Cargo.toml | 2 +- testing/test-runtime/build.rs | 8 +- 14 files changed, 103 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97ed20e562..58aac98bef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1599,26 +1599,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "gloo-net" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10" -dependencies = [ - "futures-channel", - "futures-core", - "futures-sink", - "gloo-utils", - "js-sys", - "pin-project", - "serde", - "serde_json", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "gloo-timers" version = "0.2.6" @@ -1631,19 +1611,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gloo-utils" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" -dependencies = [ - "js-sys", - "serde", - "serde_json", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "h2" version = "0.3.20" @@ -1838,10 +1805,11 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.2" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" dependencies = [ + "futures-util", "http", "hyper", "log", @@ -1849,7 +1817,6 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls", - "webpki-roots", ] [[package]] @@ -2054,9 +2021,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" +checksum = "8002beb64691edce321fc16cdba91916b10d798f9d480a05467b0ee98463c03b" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -2066,18 +2033,13 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.16.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" +checksum = "310f9566a32ec8db214805127c4f17e7e8e91015e4a1407fc1d0e84df0086a73" dependencies = [ - "anyhow", - "futures-channel", - "futures-timer", "futures-util", - "gloo-net", "http", "jsonrpsee-core", - "jsonrpsee-types", "pin-project", "rustls-native-certs", "soketto", @@ -2086,20 +2048,19 @@ dependencies = [ "tokio-rustls", "tokio-util", "tracing", - "webpki-roots", + "url", ] [[package]] name = "jsonrpsee-core" -version = "0.16.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b" +checksum = "4278372ecb78ebb522c36a242209a29162f4af0997a41158c8b60450b081baf1" dependencies = [ "anyhow", "async-lock", "async-trait", "beef", - "futures-channel", "futures-timer", "futures-util", "hyper", @@ -2115,28 +2076,29 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.16.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad" +checksum = "2393386c97ce214851a9677568c5a38223ae4eada833617cb16d8464d1128f1b" dependencies = [ "async-trait", "hyper", "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", - "rustc-hash", "serde", "serde_json", "thiserror", "tokio", + "tower", "tracing", + "url", ] [[package]] name = "jsonrpsee-types" -version = "0.16.2" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c" +checksum = "bbea61f2d95b9592491228db0c4d2b1e43ea1154ed9713bb666169cf3919ea7d" dependencies = [ "anyhow", "beef", @@ -3109,14 +3071,14 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", + "rustls-webpki", "sct", - "webpki", ] [[package]] @@ -3140,6 +3102,16 @@ dependencies = [ "base64 0.21.2", ] +[[package]] +name = "rustls-webpki" +version = "0.101.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261e9e0888cba427c3316e6322805653c9425240b6fd96cee7cb671ab70ab8d0" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -4565,13 +4537,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ "rustls", "tokio", - "webpki", ] [[package]] @@ -4617,6 +4588,27 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -4630,6 +4622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5199,25 +5192,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" -dependencies = [ - "webpki", -] - [[package]] name = "which" version = "4.4.0" diff --git a/Cargo.toml b/Cargo.toml index 2a6599e7ad..80e4f4cb66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,7 @@ getrandom = { version = "0.2", default-features = false } hex = "0.4.3" heck = "0.4.1" impl-serde = { version = "0.4.0" } -jsonrpsee = { version = "0.16" } +jsonrpsee = { version = "0.20" } pretty_assertions = "1.4.0" primitive-types = { version = "0.12.1", default-features = false, features = ["codec", "scale-info", "serde"] } proc-macro-error = "1.0.4" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b27aa858f3..68d67c96e9 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -30,5 +30,5 @@ codec = { package = "parity-scale-codec", workspace = true } scale-info = { workspace = true } scale-value = { workspace = true } syn = { workspace = true } -jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport", "http-client"] } +jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-native-tls", "http-client"] } tokio = { workspace = true, features = ["rt-multi-thread"] } diff --git a/cli/src/commands/compatibility.rs b/cli/src/commands/compatibility.rs index e35672815f..99730334e3 100644 --- a/cli/src/commands/compatibility.rs +++ b/cli/src/commands/compatibility.rs @@ -5,7 +5,7 @@ use clap::Parser as ClapParser; use codec::Decode; use color_eyre::eyre::WrapErr; -use jsonrpsee::client_transport::ws::Uri; +use jsonrpsee::client_transport::ws::Url; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use subxt_codegen::utils::MetadataVersion; @@ -16,7 +16,7 @@ use subxt_metadata::Metadata; pub struct Opts { /// Urls of the substrate nodes to verify for metadata compatibility. #[clap(name = "nodes", long, use_value_delimiter = true, value_parser)] - nodes: Vec, + nodes: Vec, /// Check the compatibility of metadata for a particular pallet. /// /// ### Note @@ -49,7 +49,7 @@ pub async fn run(opts: Opts, output: &mut impl std::io::Write) -> color_eyre::Re } async fn handle_pallet_metadata( - nodes: &[Uri], + nodes: &[Url], name: &str, version: MetadataVersion, output: &mut impl std::io::Write, @@ -63,7 +63,7 @@ async fn handle_pallet_metadata( let mut compatibility: CompatibilityPallet = Default::default(); for node in nodes.iter() { - let metadata = fetch_runtime_metadata(node, version).await?; + let metadata = fetch_runtime_metadata(node.clone(), version).await?; match metadata.pallet_by_name(name) { Some(pallet_metadata) => { @@ -97,13 +97,13 @@ async fn handle_pallet_metadata( } async fn handle_full_metadata( - nodes: &[Uri], + nodes: &[Url], version: MetadataVersion, output: &mut impl std::io::Write, ) -> color_eyre::Result<()> { let mut compatibility_map: HashMap> = HashMap::new(); for node in nodes.iter() { - let metadata = fetch_runtime_metadata(node, version).await?; + let metadata = fetch_runtime_metadata(node.clone(), version).await?; let hash = metadata.hasher().hash(); let hex_hash = hex::encode(hash); writeln!(output, "Node {node:?} has metadata hash {hex_hash:?}",)?; @@ -125,7 +125,7 @@ async fn handle_full_metadata( } async fn fetch_runtime_metadata( - url: &Uri, + url: Url, version: MetadataVersion, ) -> color_eyre::Result { let bytes = subxt_codegen::utils::fetch_metadata_bytes(url, version).await?; diff --git a/cli/src/utils.rs b/cli/src/utils.rs index 2a549b0a56..b58b57b005 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -8,7 +8,7 @@ use color_eyre::eyre; use std::str::FromStr; use std::{fs, io::Read, path::PathBuf}; -use subxt_codegen::utils::{MetadataVersion, Uri}; +use subxt_codegen::utils::{MetadataVersion, Url}; pub mod type_description; pub mod type_example; @@ -18,7 +18,7 @@ pub mod type_example; pub struct FileOrUrl { /// The url of the substrate node to query for metadata for codegen. #[clap(long, value_parser)] - pub url: Option, + pub url: Option, /// The path to the encoded metadata file. #[clap(long, value_parser)] pub file: Option, @@ -62,15 +62,15 @@ impl FileOrUrl { } // Fetch from --url (None, Some(uri), version) => Ok(subxt_codegen::utils::fetch_metadata_bytes( - uri, + uri.clone(), version.unwrap_or_default(), ) .await?), // Default if neither is provided; fetch from local url (None, None, version) => { - let uri = Uri::from_static("ws://localhost:9944"); + let url = Url::parse("ws://localhost:9944").expect("Valid URL; qed"); Ok( - subxt_codegen::utils::fetch_metadata_bytes(&uri, version.unwrap_or_default()) + subxt_codegen::utils::fetch_metadata_bytes(url, version.unwrap_or_default()) .await?, ) } @@ -109,7 +109,7 @@ impl FromStr for FileOrUrl { version: None, }) } else { - Uri::from_str(s) + Url::parse(s) .map_err(|_| "no path or uri could be crated") .map(|uri| FileOrUrl { url: Some(uri), diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 0b8a810d4b..18609661fb 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -21,7 +21,7 @@ quote = { workspace = true } syn = { workspace = true } scale-info = { workspace = true } subxt-metadata = { workspace = true } -jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport", "http-client"] } +jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-native-tls", "http-client"] } hex = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"] } thiserror = { workspace = true } diff --git a/codegen/src/api/mod.rs b/codegen/src/api/mod.rs index c814c633d2..5560b715e6 100644 --- a/codegen/src/api/mod.rs +++ b/codegen/src/api/mod.rs @@ -18,7 +18,7 @@ use crate::error::CodegenError; use crate::{ ir, types::{CompositeDef, CompositeDefFields, TypeGenerator, TypeSubstitutes}, - utils::{fetch_metadata_bytes_blocking, MetadataVersion, Uri}, + utils::{fetch_metadata_bytes_blocking, MetadataVersion, Url}, CratePath, }; use codec::Decode; @@ -144,21 +144,21 @@ impl GenerateRuntimeApi { /// # Warning /// /// Not recommended to be used in production environments. - pub fn generate_from_url(self, url: &Uri) -> Result { - fn fetch_metadata(url: &Uri, version: MetadataVersion) -> Result { + pub fn generate_from_url(self, url: Url) -> Result { + fn fetch_metadata(url: Url, version: MetadataVersion) -> Result { let bytes = fetch_metadata_bytes_blocking(url, version)?; Ok(Metadata::decode(&mut &bytes[..])?) } let metadata = self .unstable_metadata - .then(|| fetch_metadata(url, MetadataVersion::Unstable).ok()) + .then(|| fetch_metadata(url.clone(), MetadataVersion::Unstable).ok()) .flatten(); let metadata = if let Some(unstable) = metadata { unstable } else { - match fetch_metadata(url, MetadataVersion::Version(15)) { + match fetch_metadata(url.clone(), MetadataVersion::Version(15)) { Ok(metadata) => metadata, Err(_) => fetch_metadata(url, MetadataVersion::Version(14))?, } diff --git a/codegen/src/utils/fetch_metadata.rs b/codegen/src/utils/fetch_metadata.rs index 4c6f5fe90e..78308bc19d 100644 --- a/codegen/src/utils/fetch_metadata.rs +++ b/codegen/src/utils/fetch_metadata.rs @@ -6,7 +6,7 @@ use crate::error::FetchMetadataError; use codec::{Decode, Encode}; use jsonrpsee::{ async_client::ClientBuilder, - client_transport::ws::{Uri, WsTransportClientBuilder}, + client_transport::ws::{Url, WsTransportClientBuilder}, core::{client::ClientT, Error}, http_client::HttpClientBuilder, rpc_params, @@ -46,7 +46,7 @@ impl std::str::FromStr for MetadataVersion { /// Returns the metadata bytes from the provided URL, blocking the current thread. pub fn fetch_metadata_bytes_blocking( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result, FetchMetadataError> { tokio_block_on(fetch_metadata_bytes(url, version)) @@ -54,7 +54,7 @@ pub fn fetch_metadata_bytes_blocking( /// Returns the raw, 0x prefixed metadata hex from the provided URL, blocking the current thread. pub fn fetch_metadata_hex_blocking( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result { tokio_block_on(fetch_metadata_hex(url, version)) @@ -71,16 +71,13 @@ fn tokio_block_on>(fut: Fut) -> T { /// Returns the metadata bytes from the provided URL. pub async fn fetch_metadata_bytes( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result, FetchMetadataError> { - let bytes = match url.scheme_str() { - Some("http") | Some("https") => fetch_metadata_http(url, version).await, - Some("ws") | Some("wss") => fetch_metadata_ws(url, version).await, - invalid_scheme => { - let scheme = invalid_scheme.unwrap_or("no scheme"); - Err(FetchMetadataError::InvalidScheme(scheme.to_owned())) - } + let bytes = match url.scheme() { + "http" | "https" => fetch_metadata_http(url, version).await, + "ws" | "wss" => fetch_metadata_ws(url, version).await, + invalid_scheme => Err(FetchMetadataError::InvalidScheme(invalid_scheme.to_owned())), }?; Ok(bytes) @@ -88,7 +85,7 @@ pub async fn fetch_metadata_bytes( /// Returns the raw, 0x prefixed metadata hex from the provided URL. pub async fn fetch_metadata_hex( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result { let bytes = fetch_metadata_bytes(url, version).await?; @@ -97,29 +94,29 @@ pub async fn fetch_metadata_hex( } async fn fetch_metadata_ws( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result, FetchMetadataError> { let (sender, receiver) = WsTransportClientBuilder::default() - .build(url.to_string().parse::().unwrap()) + .build(url) .await .map_err(|e| Error::Transport(e.into()))?; let client = ClientBuilder::default() .request_timeout(Duration::from_secs(180)) - .max_notifs_per_subscription(4096) + .max_buffer_capacity_per_subscription(4096) .build_with_tokio(sender, receiver); fetch_metadata(client, version).await } async fn fetch_metadata_http( - url: &Uri, + url: Url, version: MetadataVersion, ) -> Result, FetchMetadataError> { let client = HttpClientBuilder::default() .request_timeout(Duration::from_secs(180)) - .build(url.to_string())?; + .build(url)?; fetch_metadata(client, version).await } diff --git a/codegen/src/utils/mod.rs b/codegen/src/utils/mod.rs index 3f0e77f71e..af5c00c2ad 100644 --- a/codegen/src/utils/mod.rs +++ b/codegen/src/utils/mod.rs @@ -7,7 +7,7 @@ mod fetch_metadata; // easy access to this type needed for fetching metadata: -pub use jsonrpsee::client_transport::ws::Uri; +pub use jsonrpsee::client_transport::ws::Url; pub use fetch_metadata::{ fetch_metadata_bytes, fetch_metadata_bytes_blocking, fetch_metadata_hex, diff --git a/macro/src/lib.rs b/macro/src/lib.rs index 53190aec0e..cde0c28427 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -4,13 +4,11 @@ extern crate proc_macro; -use std::str::FromStr; - use darling::{ast::NestedMeta, FromMeta}; use proc_macro::TokenStream; use proc_macro_error::{abort_call_site, proc_macro_error}; use subxt_codegen::{ - utils::Uri, CodegenError, DerivesRegistry, GenerateRuntimeApi, TypeSubstitutes, + utils::Url, CodegenError, DerivesRegistry, GenerateRuntimeApi, TypeSubstitutes, }; use syn::{parse_macro_input, punctuated::Punctuated}; @@ -160,13 +158,13 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream { .map_or_else(|err| err.into_compile_error().into(), Into::into) } (None, Some(url_string)) => { - let url = Uri::from_str(&url_string).unwrap_or_else(|_| { + let url = Url::parse(&url_string).unwrap_or_else(|_| { abort_call_site!("Cannot download metadata; invalid url: {}", url_string) }); runtime_api_generator .unstable_metadata(unstable_metadata) - .generate_from_url(&url) + .generate_from_url(url) .map_or_else(|err| err.into_compile_error().into(), Into::into) } (None, None) => { diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 53d586318f..1a0c73b045 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -23,7 +23,7 @@ default = ["jsonrpsee", "native"] # Exactly 1 of "web" and "native" is expected. native = [ "jsonrpsee?/async-client", - "jsonrpsee?/client-ws-transport", + "jsonrpsee?/client-ws-transport-native-tls", "subxt-lightclient?/native" ] @@ -31,7 +31,7 @@ native = [ # Exactly 1 of "web" and "native" is expected. web = [ "jsonrpsee?/async-wasm-client", - "jsonrpsee?/client-web-transport", + "jsonrpsee?/client-ws-transport-native-tls", "getrandom/js", "subxt-lightclient?/web" ] diff --git a/subxt/src/client/online_client.rs b/subxt/src/client/online_client.rs index 7ab7474da2..44ba98f446 100644 --- a/subxt/src/client/online_client.rs +++ b/subxt/src/client/online_client.rs @@ -449,7 +449,7 @@ impl Update { #[cfg(all(feature = "jsonrpsee", feature = "native"))] mod jsonrpsee_helpers { pub use jsonrpsee::{ - client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder}, + client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder}, core::{ client::{Client, ClientBuilder}, Error, @@ -459,15 +459,13 @@ mod jsonrpsee_helpers { /// Build WS RPC client from URL pub async fn client(url: &str) -> Result { let (sender, receiver) = ws_transport(url).await?; - Ok(ClientBuilder::default() - .max_notifs_per_subscription(4096) + Ok(Client::builder() + .max_buffer_capacity_per_subscription(4096) .build_with_tokio(sender, receiver)) } async fn ws_transport(url: &str) -> Result<(Sender, Receiver), Error> { - let url: Uri = url - .parse() - .map_err(|e: InvalidUri| Error::Transport(e.into()))?; + let url = Url::parse(url).map_err(|e| Error::Transport(e.into()))?; WsTransportClientBuilder::default() .build(url) .await @@ -492,7 +490,7 @@ mod jsonrpsee_helpers { .await .map_err(|e| Error::Transport(e.into()))?; Ok(ClientBuilder::default() - .max_notifs_per_subscription(4096) + .max_buffer_capacity_per_subscription(4096) .build_with_wasm(sender, receiver)) } } diff --git a/testing/test-runtime/Cargo.toml b/testing/test-runtime/Cargo.toml index 07036e8c10..b9bff1e3f9 100644 --- a/testing/test-runtime/Cargo.toml +++ b/testing/test-runtime/Cargo.toml @@ -13,6 +13,6 @@ impl-serde = { workspace = true } serde = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"] } which = { workspace = true } -jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport"] } +jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-native-tls"] } hex = { workspace = true } codec = { workspace = true } diff --git a/testing/test-runtime/build.rs b/testing/test-runtime/build.rs index 826bef1570..7198b90fa0 100644 --- a/testing/test-runtime/build.rs +++ b/testing/test-runtime/build.rs @@ -102,7 +102,7 @@ async fn run() { // Use jsonrpsee to obtain metadata from the node. mod client { pub use jsonrpsee::{ - client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder}, + client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder}, core::{ client::{Client, ClientBuilder}, Error, @@ -114,13 +114,11 @@ mod client { /// Build WS RPC client from URL pub async fn build(url: &str) -> Result { let (sender, receiver) = ws_transport(url).await?; - Ok(ClientBuilder::default().build_with_tokio(sender, receiver)) + Ok(Client::builder().build_with_tokio(sender, receiver)) } async fn ws_transport(url: &str) -> Result<(Sender, Receiver), Error> { - let url: Uri = url - .parse() - .map_err(|e: InvalidUri| Error::Transport(e.into()))?; + let url = Url::parse(url).map_err(|e| Error::Transport(e.into()))?; WsTransportClientBuilder::default() .build(url) .await From c31f3c9fbb93d71e37451d36022e9a55e723620e Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 14 Aug 2023 10:54:15 +0200 Subject: [PATCH 2/3] fix nit, revert web feature --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++++ subxt/Cargo.toml | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 58aac98bef..23bfc7eb17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1599,6 +1599,27 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-net" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a66b4e3c7d9ed8d315fd6b97c8b1f74a7c6ecbbc2320e65ae7ed38b7068cc620" +dependencies = [ + "futures-channel", + "futures-core", + "futures-sink", + "gloo-utils", + "http", + "js-sys", + "pin-project", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "gloo-timers" version = "0.2.6" @@ -1611,6 +1632,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gloo-utils" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "h2" version = "0.3.20" @@ -2037,7 +2071,9 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "310f9566a32ec8db214805127c4f17e7e8e91015e4a1407fc1d0e84df0086a73" dependencies = [ + "futures-channel", "futures-util", + "gloo-net", "http", "jsonrpsee-core", "pin-project", diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index 1a0c73b045..13b5a27183 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -31,7 +31,7 @@ native = [ # Exactly 1 of "web" and "native" is expected. web = [ "jsonrpsee?/async-wasm-client", - "jsonrpsee?/client-ws-transport-native-tls", + "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web" ] From 0a14136dac65f01e7a3a58993301db91225621a4 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 14 Aug 2023 11:11:03 +0200 Subject: [PATCH 3/3] fix lightclient code --- subxt/src/client/lightclient/builder.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/subxt/src/client/lightclient/builder.rs b/subxt/src/client/lightclient/builder.rs index 51e72c4b60..d80ea23d22 100644 --- a/subxt/src/client/lightclient/builder.rs +++ b/subxt/src/client/lightclient/builder.rs @@ -172,28 +172,26 @@ async fn fetch_url(url: impl AsRef) -> Result { mod jsonrpsee_helpers { use crate::error::{Error, LightClientError}; pub use jsonrpsee::{ - client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder}, + client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder}, core::client::{Client, ClientBuilder}, }; /// Build WS RPC client from URL pub async fn client(url: &str) -> Result { - let url = url - .parse::() - .map_err(|_| Error::LightClient(LightClientError::InvalidUrl))?; + let url = Url::parse(url).map_err(|_| Error::LightClient(LightClientError::InvalidUrl))?; - if url.scheme_str() != Some("ws") && url.scheme_str() != Some("wss") { + if url.scheme() != "ws" && url.scheme() != "wss" { return Err(Error::LightClient(LightClientError::InvalidScheme)); } let (sender, receiver) = ws_transport(url).await?; - Ok(ClientBuilder::default() - .max_notifs_per_subscription(4096) + Ok(Client::builder() + .max_buffer_capacity_per_subscription(4096) .build_with_tokio(sender, receiver)) } - async fn ws_transport(url: Uri) -> Result<(Sender, Receiver), Error> { + async fn ws_transport(url: Url) -> Result<(Sender, Receiver), Error> { WsTransportClientBuilder::default() .build(url) .await @@ -216,7 +214,7 @@ mod jsonrpsee_helpers { .map_err(|_| Error::LightClient(LightClientError::Handshake))?; Ok(ClientBuilder::default() - .max_notifs_per_subscription(4096) + .max_buffer_capacity_per_subscription(4096) .build_with_wasm(sender, receiver)) } }