Skip to content

Commit

Permalink
fix: use SafeUrl as &str, jsonrpsee 0.20.0 fixed the issue
Browse files Browse the repository at this point in the history
- the previous issue with jsonrpsee correctly parsing the &str from
  SafeUrl seems to be solved on the latest 0.20.0 release, as per the
  discussion and CHANGELOG: https://github.com/paritytech/jsonrpsee/blob/v0.20.x/CHANGELOG.md#changed-2
  and PR: paritytech/jsonrpsee#1172
  • Loading branch information
oleonardolima committed Nov 10, 2023
1 parent 6a2b828 commit 908273d
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions fedimint-core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,13 @@ impl JsonRpcClient for WsClient {
return WsClientBuilder::default()
.use_webpki_rustls()
.max_concurrent_requests(u16::MAX as usize)
.build(url_to_string_with_default_port(url)) // Hack for default ports, see fn docs
.build(url.as_str()) // Hack for default ports, see fn docs
.await;

#[cfg(target_family = "wasm")]
WsClientBuilder::default()
.max_concurrent_requests(u16::MAX as usize)
.build(url_to_string_with_default_port(url)) // Hack for default ports, see fn docs
.build(url.as_str()) // Hack for default ports, see fn docs
.await
}

Expand Down Expand Up @@ -862,24 +862,6 @@ impl<C: JsonRpcClient> FederationPeer<C> {
}
}

/// `jsonrpsee` converts the `SafeUrl` to a `&str` internally and then parses it
/// as an `Uri`. Unfortunately the underlying `Url` type swallows ports that it
/// considers default ports (e.g. 80 and 443 for HTTP(S)) which makes the `Uri`
/// parsing fail in these cases. This function works around this limitation in a
/// limited way (not fully standard compliant, but work for our use case).
///
/// See <https://github.com/paritytech/jsonrpsee/issues/554#issue-1048646896>
fn url_to_string_with_default_port(url: &SafeUrl) -> String {
format!(
"{}://{}:{}{}",
url.scheme(),
url.host().expect("Asserted on construction"),
url.port_or_known_default()
.expect("Asserted on construction"),
url.path()
)
}

impl<C: JsonRpcClient> WsFederationApi<C> {}

/// The status of a server, including how it views its peers
Expand Down

0 comments on commit 908273d

Please sign in to comment.