Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 56 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wierd; I updated jsonrpsee to 0.19 not long ago; I wonder where those changes went!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe I got distracted and never actually merged those changes, whoops!)

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"
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
14 changes: 7 additions & 7 deletions cli/src/commands/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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:?}",)?;
Expand All @@ -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?;
Expand Down
12 changes: 6 additions & 6 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>,
Expand Down Expand Up @@ -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?,
)
}
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading