oxidized_builder/network/
provider.rs1use crate::common::error::AppError;
2use alloy::network::Ethereum;
3use alloy::providers::RootProvider;
4use url::Url;
5
6pub type HttpProvider = RootProvider<Ethereum>;
8pub type WsProvider = RootProvider<Ethereum>;
9
10pub struct ConnectionFactory;
11
12impl ConnectionFactory {
13 pub fn http(rpc_url: &str) -> Result<HttpProvider, AppError> {
14 let url =
15 Url::parse(rpc_url).map_err(|e| AppError::Config(format!("Invalid RPC URL: {}", e)))?;
16
17 let provider = RootProvider::new_http(url);
18 Ok(provider)
19 }
20
21 pub async fn ws(ws_url: &str) -> Result<WsProvider, AppError> {
22 let provider = RootProvider::connect(ws_url)
23 .await
24 .map_err(|e| AppError::Connection(format!("WS Connection failed: {}", e)))?;
25
26 Ok(provider)
27 }
28}