From ed8dec54a0cf4f292ea7ee3e3934443d34cf65d9 Mon Sep 17 00:00:00 2001 From: Krishang Shah <93703995+kamuik16@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:12:50 +0530 Subject: [PATCH] feat: supports socket address as --rpc-url input (#7389) * feat: supports socket address * cargo fmt and clippy --- crates/common/src/provider/alloy.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/common/src/provider/alloy.rs b/crates/common/src/provider/alloy.rs index 7208c7953128..54c9085a15ee 100644 --- a/crates/common/src/provider/alloy.rs +++ b/crates/common/src/provider/alloy.rs @@ -12,7 +12,9 @@ use foundry_common::types::ToAlloy; use foundry_config::NamedChain; use reqwest::Url; use std::{ + net::SocketAddr, path::{Path, PathBuf}, + str::FromStr, time::Duration, }; use url::ParseError; @@ -93,12 +95,16 @@ impl ProviderBuilder { let url = Url::parse(url_str) .or_else(|err| match err { ParseError::RelativeUrlWithoutBase => { - let path = Path::new(url_str); - - if let Ok(path) = resolve_path(path) { - Url::parse(&format!("file://{}", path.display())) + if SocketAddr::from_str(url_str).is_ok() { + Url::parse(&format!("http://{}", url_str)) } else { - Err(err) + let path = Path::new(url_str); + + if let Ok(path) = resolve_path(path) { + Url::parse(&format!("file://{}", path.display())) + } else { + Err(err) + } } } _ => Err(err),