From d10b385e124f8d855c1735e8ffd34c7a3f01eadf Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 9 Dec 2024 17:24:16 +0100 Subject: [PATCH] fix: allow insecure connections with subxt --- engine/src/dot/rpc.rs | 14 +++++++++++--- utilities/scale-json-event-logger/src/main.rs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/src/dot/rpc.rs b/engine/src/dot/rpc.rs index 220057880e..9956cee9bc 100644 --- a/engine/src/dot/rpc.rs +++ b/engine/src/dot/rpc.rs @@ -40,7 +40,7 @@ macro_rules! refresh_connection_on_error { ); let new_client = - OnlineClient::::from_url(&$self.polkadot_network_ws_url).await?; + OnlineClient::::from_insecure_url(&$self.polkadot_network_ws_url).await?; let result = new_client.$namespace().$method($($arg,)*).await.map_err(|e| anyhow!("Failed to query {} Polkadot with error: {e}", stringify!($method))); let mut online_client_guard = $self.online_client.write().await; *online_client_guard = new_client; @@ -53,8 +53,12 @@ macro_rules! refresh_connection_on_error { impl DotRpcClient { pub async fn new(polkadot_network_ws_url: &str, http_client: DotHttpRpcClient) -> Result { + if subxt::utils::validate_url_is_secure(polkadot_network_ws_url).is_err() { + warn!("Using insecure Polkadot websocket endpoint: {polkadot_network_ws_url}"); + } + let online_client = Arc::new(RwLock::new( - OnlineClient::::from_url(polkadot_network_ws_url).await?, + OnlineClient::::from_insecure_url(polkadot_network_ws_url).await?, )); Ok(Self { online_client, @@ -186,7 +190,11 @@ async fn create_online_client( ws_endpoint: &SecretUrl, expected_genesis_hash: Option, ) -> Result> { - let client = OnlineClient::::from_url(ws_endpoint).await?; + if subxt::utils::validate_url_is_secure(ws_endpoint.as_ref()).is_err() { + warn!("Using insecure Polkadot websocket endpoint: {ws_endpoint}"); + } + + let client = OnlineClient::::from_insecure_url(ws_endpoint).await?; if let Some(expected_genesis_hash) = expected_genesis_hash { let genesis_hash = client.genesis_hash(); diff --git a/utilities/scale-json-event-logger/src/main.rs b/utilities/scale-json-event-logger/src/main.rs index 74935939d8..b1f763f521 100644 --- a/utilities/scale-json-event-logger/src/main.rs +++ b/utilities/scale-json-event-logger/src/main.rs @@ -88,7 +88,7 @@ async fn main() -> anyhow::Result<()> { // Any remaining arguments are assumed to be path filters. let filter = PathFilter(std::env::args().skip(3).collect::>()); - let client = subxt::OnlineClient::::from_url(url).await.unwrap(); + let client = subxt::OnlineClient::::from_insecure_url(url).await.unwrap(); match hash_opt { HashOption::Latest => {