From f90dc393d0d3f2f330032b7b84fef301ae13deaf Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 20 Jul 2024 13:32:57 +0530 Subject: [PATCH] update: rename : build_da_client in DaConfig to build_client --- .../da-clients/da-client-interface/src/lib.rs | 2 +- crates/da-clients/ethereum/src/config.rs | 2 +- crates/da-clients/ethereum/src/lib.rs | 2 +- crates/orchestrator/src/config.rs | 2 +- crates/utils/src/env_utils.rs | 18 +++++------------- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/crates/da-clients/da-client-interface/src/lib.rs b/crates/da-clients/da-client-interface/src/lib.rs index bca97748..f6158e17 100644 --- a/crates/da-clients/da-client-interface/src/lib.rs +++ b/crates/da-clients/da-client-interface/src/lib.rs @@ -33,5 +33,5 @@ pub trait DaClient: Send + Sync { pub trait DaConfig { /// Should create a new instance of the DaConfig from the environment variables fn new_from_env() -> Self; - async fn build_da_client(&self) -> T; + async fn build_client(&self) -> T; } diff --git a/crates/da-clients/ethereum/src/config.rs b/crates/da-clients/ethereum/src/config.rs index 1ac9868a..807c0492 100644 --- a/crates/da-clients/ethereum/src/config.rs +++ b/crates/da-clients/ethereum/src/config.rs @@ -27,7 +27,7 @@ impl DaConfig for EthereumDaConfig { private_key: get_env_var_or_panic("PRIVATE_KEY"), } } - async fn build_da_client(&self) -> EthereumDaClient{ + async fn build_client(&self) -> EthereumDaClient{ let client = RpcClient::new_http(Url::from_str(self.rpc_url.as_str()).expect("Failed to parse ETHEREUM_RPC_URL")); let provider = ProviderBuilder::<_, Ethereum>::new().on_client(client); let wallet: LocalWallet = env::var("PK").expect("PK must be set").parse().expect("issue while parsing"); diff --git a/crates/da-clients/ethereum/src/lib.rs b/crates/da-clients/ethereum/src/lib.rs index 3ad22b4e..5c1c30e0 100644 --- a/crates/da-clients/ethereum/src/lib.rs +++ b/crates/da-clients/ethereum/src/lib.rs @@ -17,7 +17,6 @@ use c_kzg::{Blob, KzgCommitment, KzgProof, KzgSettings}; use color_eyre::Result; use da_client_interface::{DaClient, DaVerificationStatus}; use dotenv::dotenv; -use std::path::Path; use mockall::automock; use mockall::predicate::*; use reqwest::Client; @@ -133,6 +132,7 @@ async fn prepare_sidecar( mod tests { use std::fs::File; use std::io::{self, BufRead}; + use std::path::Path; use super::*; diff --git a/crates/orchestrator/src/config.rs b/crates/orchestrator/src/config.rs index 80e176b6..a2d82858 100644 --- a/crates/orchestrator/src/config.rs +++ b/crates/orchestrator/src/config.rs @@ -138,7 +138,7 @@ async fn build_da_client() -> Box { match get_env_var_or_panic("DA_LAYER").as_str() { "ethereum" => { let config = EthereumDaConfig::new_from_env(); - Box::new(config.build_da_client().await) + Box::new(config.build_client().await) } _ => panic!("Unsupported DA layer"), } diff --git a/crates/utils/src/env_utils.rs b/crates/utils/src/env_utils.rs index 1a573f3a..327bd478 100644 --- a/crates/utils/src/env_utils.rs +++ b/crates/utils/src/env_utils.rs @@ -1,27 +1,19 @@ use std::env::VarError; - pub fn get_env_var(key: &str) -> Result { std::env::var(key) } -pub fn get_env_var_optional(key: &str) -> Result,VarError> { - match get_env_var(key){ - Ok(s) => { - Ok(Some(s)) - } - Err(VarError::NotPresent) => { - Ok(None) - } - Err(e) => { - Err(e) - } +pub fn get_env_var_optional(key: &str) -> Result, VarError> { + match get_env_var(key) { + Ok(s) => Ok(Some(s)), + Err(VarError::NotPresent) => Ok(None), + Err(e) => Err(e), } } pub fn get_env_car_optional_or_panic(key: &str) -> Option { get_env_var_optional(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e)) - } pub fn get_env_var_or_panic(key: &str) -> String {