-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
use da_client_interface::DaConfig; | ||
use std::fs::File; | ||
use std::path::PathBuf; | ||
use utils::env_utils::get_env_var_or_panic; | ||
use async_trait::async_trait; | ||
use serde::Deserialize; | ||
use dotenv::dotenv; | ||
use celestia_rpc::Client; | ||
use utils::env_utils::{get_env_car_optional_or_panic, get_env_var_or_panic}; | ||
|
||
#[derive(Clone, PartialEq, Deserialize, Debug)] | ||
pub struct CelestiaDaConfig { | ||
pub http_provider: String, | ||
pub auth_token: Option<String>, | ||
pub nid: String, | ||
} | ||
|
||
impl TryFrom<&PathBuf> for CelestiaDaConfig { | ||
type Error = String; | ||
|
||
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> { | ||
let file = File::open(path).map_err(|e| format!("error opening da config: {e}"))?; | ||
serde_json::from_reader(file).map_err(|e| format!("error parsing da config: {e}")) | ||
} | ||
} | ||
|
||
impl DaConfig for CelestiaDaConfig { | ||
#[async_trait] | ||
impl DaConfig<Client> for CelestiaDaConfig { | ||
// TODO: Possibility to merge these two ? | ||
fn new_from_env() -> Self { | ||
dotenv().ok(); | ||
Self { | ||
http_provider: get_env_var_or_panic("CELESTIA_DA_RPC_URL"), | ||
auth_token: Some(get_env_var_or_panic("CELESTIA_DA_AUTH_TOKEN")), | ||
nid: get_env_var_or_panic("CELESTIA_DA_NID"), | ||
// http_provider: get_env_var_or_panic("CELESTIA_DA_RPC_URL"), | ||
http_provider: "http://localhost:8000".to_string(), | ||
// auth_token: get_env_car_optional_or_panic("CELESTIA_DA_AUTH_TOKEN"), | ||
auth_token: None, | ||
nid: "karnot".to_string(), | ||
} | ||
} | ||
} | ||
async fn build_da_client(&self) -> Client{ | ||
Client::new(&self.http_provider, self.auth_token.as_deref()).await.expect("Failed to create Client: ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters