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
+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),