diff --git a/crates/cli/src/parse/source.rs b/crates/cli/src/parse/source.rs index e79bdb6..a778037 100644 --- a/crates/cli/src/parse/source.rs +++ b/crates/cli/src/parse/source.rs @@ -25,6 +25,12 @@ pub(crate) async fn parse_source(args: &Args) -> Result { })?; let chain_id = provider.get_chainid().await.map_err(ParseError::ProviderError)?.as_u64(); (provider.into(), chain_id) + } else if rpc_url.ends_with(".ipc") { + let provider: Provider = Provider::connect_ipc(&rpc_url).await.map_err(|_| { + ParseError::ParseError("could not instantiate HTTP Provider".to_string()) + })?; + let chain_id = provider.get_chainid().await.map_err(ParseError::ProviderError)?.as_u64(); + (provider.into(), chain_id) } else { return Err(ParseError::ParseError(format!("invalid rpc url: {}", rpc_url))); }; @@ -81,7 +87,7 @@ pub(crate) fn parse_rpc_url(args: &Args) -> Result { } }, }; - if !url.starts_with("http") & !url.starts_with("ws") { + if !url.starts_with("http") & !url.starts_with("ws") & !url.ends_with(".ipc") { url = "http://".to_string() + url.as_str(); }; Ok(url) diff --git a/crates/freeze/src/types/sources.rs b/crates/freeze/src/types/sources.rs index f45d774..4c5107b 100644 --- a/crates/freeze/src/types/sources.rs +++ b/crates/freeze/src/types/sources.rs @@ -37,19 +37,6 @@ pub struct Source { pub labels: SourceLabels, } -// impl { -// fn default() -> Self { -// pub struct Source { -// pub inner_request_size: DEFAULT_INNER_REQUEST_SIZE, -// pub max_concurrent_chunks: DEFAULT_MAX_CONCURRENT_CHUNKS, -// pub rpc_url: String, -// pub semaphore: Option>, -// pub rate_limiter: Option>, -// pub labels: SourceLabels, -// } -// } -// } - /// A non-generic wrapper over different provider types for use as a trait object #[derive(Clone, Debug)] pub enum ProviderWrapper { @@ -59,6 +46,14 @@ pub enum ProviderWrapper { RetryClientHttp(Arc>>), /// websocket client WsClient(Arc>), + /// ipc client + IpcClient(Arc>), +} + +impl From> for ProviderWrapper { + fn from(value: Provider) -> ProviderWrapper { + ProviderWrapper::MockProvider(Arc::new(value)) + } } impl From>> for ProviderWrapper { @@ -73,9 +68,9 @@ impl From> for ProviderWrapper { } } -impl From> for ProviderWrapper { - fn from(value: Provider) -> ProviderWrapper { - ProviderWrapper::MockProvider(Arc::new(value)) +impl From> for ProviderWrapper { + fn from(value: Provider) -> ProviderWrapper { + ProviderWrapper::IpcClient(Arc::new(value)) } } @@ -87,34 +82,11 @@ macro_rules! source_provider { ProviderWrapper::MockProvider(provider) => provider.$method($($arg),*), ProviderWrapper::RetryClientHttp(provider) => provider.$method($($arg),*), ProviderWrapper::WsClient(provider) => provider.$method($($arg),*), + ProviderWrapper::IpcClient(provider) => provider.$method($($arg),*), } }; } -// impl Source { -// // pub async fn get_block(&self, block_num: u64) -> Result>> { -// // let _permit = self.permit_request().await; -// // Self::map_err(source_provider!(self, get_block(block_num)).await) -// // } - -// async fn permit_request( -// &self, -// ) -> Option<::core::result::Result, AcquireError>> { -// let permit = match &self.semaphore { -// Some(semaphore) => Some(semaphore.acquire().await), -// _ => None, -// }; -// if let Some(limiter) = &self.rate_limiter { -// limiter.until_ready().await; -// } -// permit -// } - -// fn map_err(res: ::core::result::Result) -> Result { -// res.map_err(CollectError::ProviderError) -// } -// } - impl Source { /// Returns all receipts for a block. /// Tries to use `eth_getBlockReceipts` first, and falls back to `eth_getTransactionReceipt`