refactor(rpc): support default port in URL (#1122)

* refactor: support default port in URL

Update jsonrpsee to v0.20 to support the default port number in URLs.

* fix nit, revert web feature

* fix lightclient code
This commit is contained in:
Niklas Adolfsson
2023-08-15 10:53:26 +02:00
committed by GitHub
parent 751e738d8f
commit 8b4fea0b07
15 changed files with 112 additions and 113 deletions
Generated
+56 -46
View File
@@ -1601,14 +1601,15 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gloo-net"
version = "0.2.6"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10"
checksum = "a66b4e3c7d9ed8d315fd6b97c8b1f74a7c6ecbbc2320e65ae7ed38b7068cc620"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"gloo-utils",
"http",
"js-sys",
"pin-project",
"serde",
@@ -1838,10 +1839,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 +1851,6 @@ dependencies = [
"rustls-native-certs",
"tokio",
"tokio-rustls",
"webpki-roots",
]
[[package]]
@@ -2054,9 +2055,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 +2067,15 @@ 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 +2084,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 +2112,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 +3107,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 +3138,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"
@@ -4574,13 +4582,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]]
@@ -4626,6 +4633,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"
@@ -4639,6 +4667,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@@ -5208,25 +5237,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"
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"] }
+7 -7
View File
@@ -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<Uri>,
nodes: Vec<Url>,
/// 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<String, Vec<String>> = 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<Metadata> {
let bytes = subxt_codegen::utils::fetch_metadata_bytes(url, version).await?;
+6 -6
View File
@@ -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<Uri>,
pub url: Option<Url>,
/// The path to the encoded metadata file.
#[clap(long, value_parser)]
pub file: Option<PathBuf>,
@@ -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),
+1 -1
View File
@@ -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 }
+5 -5
View File
@@ -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<TokenStream2, CodegenError> {
fn fetch_metadata(url: &Uri, version: MetadataVersion) -> Result<Metadata, CodegenError> {
pub fn generate_from_url(self, url: Url) -> Result<TokenStream2, CodegenError> {
fn fetch_metadata(url: Url, version: MetadataVersion) -> Result<Metadata, CodegenError> {
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))?,
}
+14 -17
View File
@@ -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<Vec<u8>, 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<String, FetchMetadataError> {
tokio_block_on(fetch_metadata_hex(url, version))
@@ -71,16 +71,13 @@ fn tokio_block_on<T, Fut: std::future::Future<Output = T>>(fut: Fut) -> T {
/// Returns the metadata bytes from the provided URL.
pub async fn fetch_metadata_bytes(
url: &Uri,
url: Url,
version: MetadataVersion,
) -> Result<Vec<u8>, 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<String, FetchMetadataError> {
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<Vec<u8>, FetchMetadataError> {
let (sender, receiver) = WsTransportClientBuilder::default()
.build(url.to_string().parse::<Uri>().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<Vec<u8>, FetchMetadataError> {
let client = HttpClientBuilder::default()
.request_timeout(Duration::from_secs(180))
.build(url.to_string())?;
.build(url)?;
fetch_metadata(client, version).await
}
+1 -1
View File
@@ -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,
+3 -5
View File
@@ -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) => {
+1 -1
View File
@@ -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"
]
+7 -9
View File
@@ -172,28 +172,26 @@ async fn fetch_url(url: impl AsRef<str>) -> Result<serde_json::Value, Error> {
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<Client, Error> {
let url = url
.parse::<Uri>()
.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))
}
}
+5 -7
View File
@@ -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<Client, Error> {
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))
}
}
+1 -1
View File
@@ -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 }
+3 -5
View File
@@ -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<Client, Error> {
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