Skip to content

Commit

Permalink
update: rename : build_da_client in DaConfig to build_client
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Jul 20, 2024
1 parent 241f32d commit f90dc39
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/da-clients/da-client-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ pub trait DaClient: Send + Sync {
pub trait DaConfig<T> {
/// 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;
}
2 changes: 1 addition & 1 deletion crates/da-clients/ethereum/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DaConfig<EthereumDaClient> 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");
Expand Down
2 changes: 1 addition & 1 deletion crates/da-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
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"),
}
Expand Down
18 changes: 5 additions & 13 deletions crates/utils/src/env_utils.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
use std::env::VarError;


pub fn get_env_var(key: &str) -> Result<String, VarError> {
std::env::var(key)
}

pub fn get_env_var_optional(key: &str) -> Result<Option<String>,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<Option<String>, 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<String> {
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 {
Expand Down

0 comments on commit f90dc39

Please sign in to comment.