mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
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:
Generated
+56
-46
@@ -1601,14 +1601,15 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gloo-net"
|
name = "gloo-net"
|
||||||
version = "0.2.6"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10"
|
checksum = "a66b4e3c7d9ed8d315fd6b97c8b1f74a7c6ecbbc2320e65ae7ed38b7068cc620"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"gloo-utils",
|
"gloo-utils",
|
||||||
|
"http",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1838,10 +1839,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-rustls"
|
name = "hyper-rustls"
|
||||||
version = "0.23.2"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
|
checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"hyper",
|
"hyper",
|
||||||
"log",
|
"log",
|
||||||
@@ -1849,7 +1851,6 @@ dependencies = [
|
|||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"webpki-roots",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2054,9 +2055,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee"
|
name = "jsonrpsee"
|
||||||
version = "0.16.2"
|
version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e"
|
checksum = "8002beb64691edce321fc16cdba91916b10d798f9d480a05467b0ee98463c03b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jsonrpsee-client-transport",
|
"jsonrpsee-client-transport",
|
||||||
"jsonrpsee-core",
|
"jsonrpsee-core",
|
||||||
@@ -2066,18 +2067,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-client-transport"
|
name = "jsonrpsee-client-transport"
|
||||||
version = "0.16.2"
|
version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb"
|
checksum = "310f9566a32ec8db214805127c4f17e7e8e91015e4a1407fc1d0e84df0086a73"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-timer",
|
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"gloo-net",
|
"gloo-net",
|
||||||
"http",
|
"http",
|
||||||
"jsonrpsee-core",
|
"jsonrpsee-core",
|
||||||
"jsonrpsee-types",
|
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
"soketto",
|
"soketto",
|
||||||
@@ -2086,20 +2084,19 @@ dependencies = [
|
|||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tracing",
|
"tracing",
|
||||||
"webpki-roots",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-core"
|
name = "jsonrpsee-core"
|
||||||
version = "0.16.2"
|
version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b"
|
checksum = "4278372ecb78ebb522c36a242209a29162f4af0997a41158c8b60450b081baf1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-lock",
|
"async-lock",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"beef",
|
"beef",
|
||||||
"futures-channel",
|
|
||||||
"futures-timer",
|
"futures-timer",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
@@ -2115,28 +2112,29 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-http-client"
|
name = "jsonrpsee-http-client"
|
||||||
version = "0.16.2"
|
version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad"
|
checksum = "2393386c97ce214851a9677568c5a38223ae4eada833617cb16d8464d1128f1b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-rustls",
|
"hyper-rustls",
|
||||||
"jsonrpsee-core",
|
"jsonrpsee-core",
|
||||||
"jsonrpsee-types",
|
"jsonrpsee-types",
|
||||||
"rustc-hash",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tower",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpsee-types"
|
name = "jsonrpsee-types"
|
||||||
version = "0.16.2"
|
version = "0.20.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c"
|
checksum = "bbea61f2d95b9592491228db0c4d2b1e43ea1154ed9713bb666169cf3919ea7d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"beef",
|
"beef",
|
||||||
@@ -3109,14 +3107,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.20.8"
|
version = "0.21.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
|
checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"ring",
|
"ring",
|
||||||
|
"rustls-webpki",
|
||||||
"sct",
|
"sct",
|
||||||
"webpki",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3140,6 +3138,16 @@ dependencies = [
|
|||||||
"base64 0.21.2",
|
"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]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.14"
|
version = "1.0.14"
|
||||||
@@ -4574,13 +4582,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-rustls"
|
name = "tokio-rustls"
|
||||||
version = "0.23.4"
|
version = "0.24.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
|
checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"tokio",
|
"tokio",
|
||||||
"webpki",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4626,6 +4633,27 @@ dependencies = [
|
|||||||
"winnow",
|
"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]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -4639,6 +4667,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
"log",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
@@ -5208,25 +5237,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"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]]
|
[[package]]
|
||||||
name = "which"
|
name = "which"
|
||||||
version = "4.4.0"
|
version = "4.4.0"
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ getrandom = { version = "0.2", default-features = false }
|
|||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
heck = "0.4.1"
|
heck = "0.4.1"
|
||||||
impl-serde = { version = "0.4.0" }
|
impl-serde = { version = "0.4.0" }
|
||||||
jsonrpsee = { version = "0.16" }
|
jsonrpsee = { version = "0.20" }
|
||||||
pretty_assertions = "1.4.0"
|
pretty_assertions = "1.4.0"
|
||||||
primitive-types = { version = "0.12.1", default-features = false, features = ["codec", "scale-info", "serde"] }
|
primitive-types = { version = "0.12.1", default-features = false, features = ["codec", "scale-info", "serde"] }
|
||||||
proc-macro-error = "1.0.4"
|
proc-macro-error = "1.0.4"
|
||||||
|
|||||||
+1
-1
@@ -30,5 +30,5 @@ codec = { package = "parity-scale-codec", workspace = true }
|
|||||||
scale-info = { workspace = true }
|
scale-info = { workspace = true }
|
||||||
scale-value = { workspace = true }
|
scale-value = { workspace = true }
|
||||||
syn = { 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"] }
|
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
use clap::Parser as ClapParser;
|
use clap::Parser as ClapParser;
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use color_eyre::eyre::WrapErr;
|
use color_eyre::eyre::WrapErr;
|
||||||
use jsonrpsee::client_transport::ws::Uri;
|
use jsonrpsee::client_transport::ws::Url;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use subxt_codegen::utils::MetadataVersion;
|
use subxt_codegen::utils::MetadataVersion;
|
||||||
@@ -16,7 +16,7 @@ use subxt_metadata::Metadata;
|
|||||||
pub struct Opts {
|
pub struct Opts {
|
||||||
/// Urls of the substrate nodes to verify for metadata compatibility.
|
/// Urls of the substrate nodes to verify for metadata compatibility.
|
||||||
#[clap(name = "nodes", long, use_value_delimiter = true, value_parser)]
|
#[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.
|
/// Check the compatibility of metadata for a particular pallet.
|
||||||
///
|
///
|
||||||
/// ### Note
|
/// ### 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(
|
async fn handle_pallet_metadata(
|
||||||
nodes: &[Uri],
|
nodes: &[Url],
|
||||||
name: &str,
|
name: &str,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
output: &mut impl std::io::Write,
|
output: &mut impl std::io::Write,
|
||||||
@@ -63,7 +63,7 @@ async fn handle_pallet_metadata(
|
|||||||
|
|
||||||
let mut compatibility: CompatibilityPallet = Default::default();
|
let mut compatibility: CompatibilityPallet = Default::default();
|
||||||
for node in nodes.iter() {
|
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) {
|
match metadata.pallet_by_name(name) {
|
||||||
Some(pallet_metadata) => {
|
Some(pallet_metadata) => {
|
||||||
@@ -97,13 +97,13 @@ async fn handle_pallet_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_full_metadata(
|
async fn handle_full_metadata(
|
||||||
nodes: &[Uri],
|
nodes: &[Url],
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
output: &mut impl std::io::Write,
|
output: &mut impl std::io::Write,
|
||||||
) -> color_eyre::Result<()> {
|
) -> color_eyre::Result<()> {
|
||||||
let mut compatibility_map: HashMap<String, Vec<String>> = HashMap::new();
|
let mut compatibility_map: HashMap<String, Vec<String>> = HashMap::new();
|
||||||
for node in nodes.iter() {
|
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 hash = metadata.hasher().hash();
|
||||||
let hex_hash = hex::encode(hash);
|
let hex_hash = hex::encode(hash);
|
||||||
writeln!(output, "Node {node:?} has metadata hash {hex_hash:?}",)?;
|
writeln!(output, "Node {node:?} has metadata hash {hex_hash:?}",)?;
|
||||||
@@ -125,7 +125,7 @@ async fn handle_full_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_runtime_metadata(
|
async fn fetch_runtime_metadata(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> color_eyre::Result<Metadata> {
|
) -> color_eyre::Result<Metadata> {
|
||||||
let bytes = subxt_codegen::utils::fetch_metadata_bytes(url, version).await?;
|
let bytes = subxt_codegen::utils::fetch_metadata_bytes(url, version).await?;
|
||||||
|
|||||||
+6
-6
@@ -8,7 +8,7 @@ use color_eyre::eyre;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::{fs, io::Read, path::PathBuf};
|
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_description;
|
||||||
pub mod type_example;
|
pub mod type_example;
|
||||||
@@ -18,7 +18,7 @@ pub mod type_example;
|
|||||||
pub struct FileOrUrl {
|
pub struct FileOrUrl {
|
||||||
/// The url of the substrate node to query for metadata for codegen.
|
/// The url of the substrate node to query for metadata for codegen.
|
||||||
#[clap(long, value_parser)]
|
#[clap(long, value_parser)]
|
||||||
pub url: Option<Uri>,
|
pub url: Option<Url>,
|
||||||
/// The path to the encoded metadata file.
|
/// The path to the encoded metadata file.
|
||||||
#[clap(long, value_parser)]
|
#[clap(long, value_parser)]
|
||||||
pub file: Option<PathBuf>,
|
pub file: Option<PathBuf>,
|
||||||
@@ -62,15 +62,15 @@ impl FileOrUrl {
|
|||||||
}
|
}
|
||||||
// Fetch from --url
|
// Fetch from --url
|
||||||
(None, Some(uri), version) => Ok(subxt_codegen::utils::fetch_metadata_bytes(
|
(None, Some(uri), version) => Ok(subxt_codegen::utils::fetch_metadata_bytes(
|
||||||
uri,
|
uri.clone(),
|
||||||
version.unwrap_or_default(),
|
version.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
.await?),
|
.await?),
|
||||||
// Default if neither is provided; fetch from local url
|
// Default if neither is provided; fetch from local url
|
||||||
(None, None, version) => {
|
(None, None, version) => {
|
||||||
let uri = Uri::from_static("ws://localhost:9944");
|
let url = Url::parse("ws://localhost:9944").expect("Valid URL; qed");
|
||||||
Ok(
|
Ok(
|
||||||
subxt_codegen::utils::fetch_metadata_bytes(&uri, version.unwrap_or_default())
|
subxt_codegen::utils::fetch_metadata_bytes(url, version.unwrap_or_default())
|
||||||
.await?,
|
.await?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ impl FromStr for FileOrUrl {
|
|||||||
version: None,
|
version: None,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Uri::from_str(s)
|
Url::parse(s)
|
||||||
.map_err(|_| "no path or uri could be crated")
|
.map_err(|_| "no path or uri could be crated")
|
||||||
.map(|uri| FileOrUrl {
|
.map(|uri| FileOrUrl {
|
||||||
url: Some(uri),
|
url: Some(uri),
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ quote = { workspace = true }
|
|||||||
syn = { workspace = true }
|
syn = { workspace = true }
|
||||||
scale-info = { workspace = true }
|
scale-info = { workspace = true }
|
||||||
subxt-metadata = { 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 }
|
hex = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use crate::error::CodegenError;
|
|||||||
use crate::{
|
use crate::{
|
||||||
ir,
|
ir,
|
||||||
types::{CompositeDef, CompositeDefFields, TypeGenerator, TypeSubstitutes},
|
types::{CompositeDef, CompositeDefFields, TypeGenerator, TypeSubstitutes},
|
||||||
utils::{fetch_metadata_bytes_blocking, MetadataVersion, Uri},
|
utils::{fetch_metadata_bytes_blocking, MetadataVersion, Url},
|
||||||
CratePath,
|
CratePath,
|
||||||
};
|
};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
@@ -144,21 +144,21 @@ impl GenerateRuntimeApi {
|
|||||||
/// # Warning
|
/// # Warning
|
||||||
///
|
///
|
||||||
/// Not recommended to be used in production environments.
|
/// Not recommended to be used in production environments.
|
||||||
pub fn generate_from_url(self, url: &Uri) -> Result<TokenStream2, CodegenError> {
|
pub fn generate_from_url(self, url: Url) -> Result<TokenStream2, CodegenError> {
|
||||||
fn fetch_metadata(url: &Uri, version: MetadataVersion) -> Result<Metadata, CodegenError> {
|
fn fetch_metadata(url: Url, version: MetadataVersion) -> Result<Metadata, CodegenError> {
|
||||||
let bytes = fetch_metadata_bytes_blocking(url, version)?;
|
let bytes = fetch_metadata_bytes_blocking(url, version)?;
|
||||||
Ok(Metadata::decode(&mut &bytes[..])?)
|
Ok(Metadata::decode(&mut &bytes[..])?)
|
||||||
}
|
}
|
||||||
|
|
||||||
let metadata = self
|
let metadata = self
|
||||||
.unstable_metadata
|
.unstable_metadata
|
||||||
.then(|| fetch_metadata(url, MetadataVersion::Unstable).ok())
|
.then(|| fetch_metadata(url.clone(), MetadataVersion::Unstable).ok())
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
||||||
let metadata = if let Some(unstable) = metadata {
|
let metadata = if let Some(unstable) = metadata {
|
||||||
unstable
|
unstable
|
||||||
} else {
|
} else {
|
||||||
match fetch_metadata(url, MetadataVersion::Version(15)) {
|
match fetch_metadata(url.clone(), MetadataVersion::Version(15)) {
|
||||||
Ok(metadata) => metadata,
|
Ok(metadata) => metadata,
|
||||||
Err(_) => fetch_metadata(url, MetadataVersion::Version(14))?,
|
Err(_) => fetch_metadata(url, MetadataVersion::Version(14))?,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::error::FetchMetadataError;
|
|||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use jsonrpsee::{
|
use jsonrpsee::{
|
||||||
async_client::ClientBuilder,
|
async_client::ClientBuilder,
|
||||||
client_transport::ws::{Uri, WsTransportClientBuilder},
|
client_transport::ws::{Url, WsTransportClientBuilder},
|
||||||
core::{client::ClientT, Error},
|
core::{client::ClientT, Error},
|
||||||
http_client::HttpClientBuilder,
|
http_client::HttpClientBuilder,
|
||||||
rpc_params,
|
rpc_params,
|
||||||
@@ -46,7 +46,7 @@ impl std::str::FromStr for MetadataVersion {
|
|||||||
|
|
||||||
/// Returns the metadata bytes from the provided URL, blocking the current thread.
|
/// Returns the metadata bytes from the provided URL, blocking the current thread.
|
||||||
pub fn fetch_metadata_bytes_blocking(
|
pub fn fetch_metadata_bytes_blocking(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||||
tokio_block_on(fetch_metadata_bytes(url, version))
|
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.
|
/// Returns the raw, 0x prefixed metadata hex from the provided URL, blocking the current thread.
|
||||||
pub fn fetch_metadata_hex_blocking(
|
pub fn fetch_metadata_hex_blocking(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<String, FetchMetadataError> {
|
) -> Result<String, FetchMetadataError> {
|
||||||
tokio_block_on(fetch_metadata_hex(url, version))
|
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.
|
/// Returns the metadata bytes from the provided URL.
|
||||||
pub async fn fetch_metadata_bytes(
|
pub async fn fetch_metadata_bytes(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||||
let bytes = match url.scheme_str() {
|
let bytes = match url.scheme() {
|
||||||
Some("http") | Some("https") => fetch_metadata_http(url, version).await,
|
"http" | "https" => fetch_metadata_http(url, version).await,
|
||||||
Some("ws") | Some("wss") => fetch_metadata_ws(url, version).await,
|
"ws" | "wss" => fetch_metadata_ws(url, version).await,
|
||||||
invalid_scheme => {
|
invalid_scheme => Err(FetchMetadataError::InvalidScheme(invalid_scheme.to_owned())),
|
||||||
let scheme = invalid_scheme.unwrap_or("no scheme");
|
|
||||||
Err(FetchMetadataError::InvalidScheme(scheme.to_owned()))
|
|
||||||
}
|
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
Ok(bytes)
|
Ok(bytes)
|
||||||
@@ -88,7 +85,7 @@ pub async fn fetch_metadata_bytes(
|
|||||||
|
|
||||||
/// Returns the raw, 0x prefixed metadata hex from the provided URL.
|
/// Returns the raw, 0x prefixed metadata hex from the provided URL.
|
||||||
pub async fn fetch_metadata_hex(
|
pub async fn fetch_metadata_hex(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<String, FetchMetadataError> {
|
) -> Result<String, FetchMetadataError> {
|
||||||
let bytes = fetch_metadata_bytes(url, version).await?;
|
let bytes = fetch_metadata_bytes(url, version).await?;
|
||||||
@@ -97,29 +94,29 @@ pub async fn fetch_metadata_hex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_metadata_ws(
|
async fn fetch_metadata_ws(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||||
let (sender, receiver) = WsTransportClientBuilder::default()
|
let (sender, receiver) = WsTransportClientBuilder::default()
|
||||||
.build(url.to_string().parse::<Uri>().unwrap())
|
.build(url)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| Error::Transport(e.into()))?;
|
.map_err(|e| Error::Transport(e.into()))?;
|
||||||
|
|
||||||
let client = ClientBuilder::default()
|
let client = ClientBuilder::default()
|
||||||
.request_timeout(Duration::from_secs(180))
|
.request_timeout(Duration::from_secs(180))
|
||||||
.max_notifs_per_subscription(4096)
|
.max_buffer_capacity_per_subscription(4096)
|
||||||
.build_with_tokio(sender, receiver);
|
.build_with_tokio(sender, receiver);
|
||||||
|
|
||||||
fetch_metadata(client, version).await
|
fetch_metadata(client, version).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_metadata_http(
|
async fn fetch_metadata_http(
|
||||||
url: &Uri,
|
url: Url,
|
||||||
version: MetadataVersion,
|
version: MetadataVersion,
|
||||||
) -> Result<Vec<u8>, FetchMetadataError> {
|
) -> Result<Vec<u8>, FetchMetadataError> {
|
||||||
let client = HttpClientBuilder::default()
|
let client = HttpClientBuilder::default()
|
||||||
.request_timeout(Duration::from_secs(180))
|
.request_timeout(Duration::from_secs(180))
|
||||||
.build(url.to_string())?;
|
.build(url)?;
|
||||||
|
|
||||||
fetch_metadata(client, version).await
|
fetch_metadata(client, version).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
mod fetch_metadata;
|
mod fetch_metadata;
|
||||||
|
|
||||||
// easy access to this type needed for fetching 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::{
|
pub use fetch_metadata::{
|
||||||
fetch_metadata_bytes, fetch_metadata_bytes_blocking, fetch_metadata_hex,
|
fetch_metadata_bytes, fetch_metadata_bytes_blocking, fetch_metadata_hex,
|
||||||
|
|||||||
+3
-5
@@ -4,13 +4,11 @@
|
|||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use darling::{ast::NestedMeta, FromMeta};
|
use darling::{ast::NestedMeta, FromMeta};
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro_error::{abort_call_site, proc_macro_error};
|
use proc_macro_error::{abort_call_site, proc_macro_error};
|
||||||
use subxt_codegen::{
|
use subxt_codegen::{
|
||||||
utils::Uri, CodegenError, DerivesRegistry, GenerateRuntimeApi, TypeSubstitutes,
|
utils::Url, CodegenError, DerivesRegistry, GenerateRuntimeApi, TypeSubstitutes,
|
||||||
};
|
};
|
||||||
use syn::{parse_macro_input, punctuated::Punctuated};
|
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)
|
.map_or_else(|err| err.into_compile_error().into(), Into::into)
|
||||||
}
|
}
|
||||||
(None, Some(url_string)) => {
|
(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)
|
abort_call_site!("Cannot download metadata; invalid url: {}", url_string)
|
||||||
});
|
});
|
||||||
|
|
||||||
runtime_api_generator
|
runtime_api_generator
|
||||||
.unstable_metadata(unstable_metadata)
|
.unstable_metadata(unstable_metadata)
|
||||||
.generate_from_url(&url)
|
.generate_from_url(url)
|
||||||
.map_or_else(|err| err.into_compile_error().into(), Into::into)
|
.map_or_else(|err| err.into_compile_error().into(), Into::into)
|
||||||
}
|
}
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ default = ["jsonrpsee", "native"]
|
|||||||
# Exactly 1 of "web" and "native" is expected.
|
# Exactly 1 of "web" and "native" is expected.
|
||||||
native = [
|
native = [
|
||||||
"jsonrpsee?/async-client",
|
"jsonrpsee?/async-client",
|
||||||
"jsonrpsee?/client-ws-transport",
|
"jsonrpsee?/client-ws-transport-native-tls",
|
||||||
"subxt-lightclient?/native"
|
"subxt-lightclient?/native"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -172,28 +172,26 @@ async fn fetch_url(url: impl AsRef<str>) -> Result<serde_json::Value, Error> {
|
|||||||
mod jsonrpsee_helpers {
|
mod jsonrpsee_helpers {
|
||||||
use crate::error::{Error, LightClientError};
|
use crate::error::{Error, LightClientError};
|
||||||
pub use jsonrpsee::{
|
pub use jsonrpsee::{
|
||||||
client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder},
|
client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder},
|
||||||
core::client::{Client, ClientBuilder},
|
core::client::{Client, ClientBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Build WS RPC client from URL
|
/// Build WS RPC client from URL
|
||||||
pub async fn client(url: &str) -> Result<Client, Error> {
|
pub async fn client(url: &str) -> Result<Client, Error> {
|
||||||
let url = url
|
let url = Url::parse(url).map_err(|_| Error::LightClient(LightClientError::InvalidUrl))?;
|
||||||
.parse::<Uri>()
|
|
||||||
.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));
|
return Err(Error::LightClient(LightClientError::InvalidScheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (sender, receiver) = ws_transport(url).await?;
|
let (sender, receiver) = ws_transport(url).await?;
|
||||||
|
|
||||||
Ok(ClientBuilder::default()
|
Ok(Client::builder()
|
||||||
.max_notifs_per_subscription(4096)
|
.max_buffer_capacity_per_subscription(4096)
|
||||||
.build_with_tokio(sender, receiver))
|
.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()
|
WsTransportClientBuilder::default()
|
||||||
.build(url)
|
.build(url)
|
||||||
.await
|
.await
|
||||||
@@ -216,7 +214,7 @@ mod jsonrpsee_helpers {
|
|||||||
.map_err(|_| Error::LightClient(LightClientError::Handshake))?;
|
.map_err(|_| Error::LightClient(LightClientError::Handshake))?;
|
||||||
|
|
||||||
Ok(ClientBuilder::default()
|
Ok(ClientBuilder::default()
|
||||||
.max_notifs_per_subscription(4096)
|
.max_buffer_capacity_per_subscription(4096)
|
||||||
.build_with_wasm(sender, receiver))
|
.build_with_wasm(sender, receiver))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ impl Update {
|
|||||||
#[cfg(all(feature = "jsonrpsee", feature = "native"))]
|
#[cfg(all(feature = "jsonrpsee", feature = "native"))]
|
||||||
mod jsonrpsee_helpers {
|
mod jsonrpsee_helpers {
|
||||||
pub use jsonrpsee::{
|
pub use jsonrpsee::{
|
||||||
client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder},
|
client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder},
|
||||||
core::{
|
core::{
|
||||||
client::{Client, ClientBuilder},
|
client::{Client, ClientBuilder},
|
||||||
Error,
|
Error,
|
||||||
@@ -459,15 +459,13 @@ mod jsonrpsee_helpers {
|
|||||||
/// Build WS RPC client from URL
|
/// Build WS RPC client from URL
|
||||||
pub async fn client(url: &str) -> Result<Client, Error> {
|
pub async fn client(url: &str) -> Result<Client, Error> {
|
||||||
let (sender, receiver) = ws_transport(url).await?;
|
let (sender, receiver) = ws_transport(url).await?;
|
||||||
Ok(ClientBuilder::default()
|
Ok(Client::builder()
|
||||||
.max_notifs_per_subscription(4096)
|
.max_buffer_capacity_per_subscription(4096)
|
||||||
.build_with_tokio(sender, receiver))
|
.build_with_tokio(sender, receiver))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ws_transport(url: &str) -> Result<(Sender, Receiver), Error> {
|
async fn ws_transport(url: &str) -> Result<(Sender, Receiver), Error> {
|
||||||
let url: Uri = url
|
let url = Url::parse(url).map_err(|e| Error::Transport(e.into()))?;
|
||||||
.parse()
|
|
||||||
.map_err(|e: InvalidUri| Error::Transport(e.into()))?;
|
|
||||||
WsTransportClientBuilder::default()
|
WsTransportClientBuilder::default()
|
||||||
.build(url)
|
.build(url)
|
||||||
.await
|
.await
|
||||||
@@ -492,7 +490,7 @@ mod jsonrpsee_helpers {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| Error::Transport(e.into()))?;
|
.map_err(|e| Error::Transport(e.into()))?;
|
||||||
Ok(ClientBuilder::default()
|
Ok(ClientBuilder::default()
|
||||||
.max_notifs_per_subscription(4096)
|
.max_buffer_capacity_per_subscription(4096)
|
||||||
.build_with_wasm(sender, receiver))
|
.build_with_wasm(sender, receiver))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ impl-serde = { workspace = true }
|
|||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
||||||
which = { workspace = true }
|
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 }
|
hex = { workspace = true }
|
||||||
codec = { workspace = true }
|
codec = { workspace = true }
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ async fn run() {
|
|||||||
// Use jsonrpsee to obtain metadata from the node.
|
// Use jsonrpsee to obtain metadata from the node.
|
||||||
mod client {
|
mod client {
|
||||||
pub use jsonrpsee::{
|
pub use jsonrpsee::{
|
||||||
client_transport::ws::{InvalidUri, Receiver, Sender, Uri, WsTransportClientBuilder},
|
client_transport::ws::{Receiver, Sender, Url, WsTransportClientBuilder},
|
||||||
core::{
|
core::{
|
||||||
client::{Client, ClientBuilder},
|
client::{Client, ClientBuilder},
|
||||||
Error,
|
Error,
|
||||||
@@ -114,13 +114,11 @@ mod client {
|
|||||||
/// Build WS RPC client from URL
|
/// Build WS RPC client from URL
|
||||||
pub async fn build(url: &str) -> Result<Client, Error> {
|
pub async fn build(url: &str) -> Result<Client, Error> {
|
||||||
let (sender, receiver) = ws_transport(url).await?;
|
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> {
|
async fn ws_transport(url: &str) -> Result<(Sender, Receiver), Error> {
|
||||||
let url: Uri = url
|
let url = Url::parse(url).map_err(|e| Error::Transport(e.into()))?;
|
||||||
.parse()
|
|
||||||
.map_err(|e: InvalidUri| Error::Transport(e.into()))?;
|
|
||||||
WsTransportClientBuilder::default()
|
WsTransportClientBuilder::default()
|
||||||
.build(url)
|
.build(url)
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user