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 -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))
}
}