Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/fortuna/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ use {
tokio::sync::RwLock,
url::Url,
};
pub use {chain_ids::*, explorer::*, index::*, live::*, metrics::*, ready::*, revelation::*};
pub use {
chain_ids::*, config::*, explorer::*, index::*, live::*, metrics::*, ready::*, revelation::*,
};

mod chain_ids;
mod config;
mod explorer;
mod index;
mod live;
Expand Down Expand Up @@ -211,6 +214,7 @@ pub fn routes(state: ApiState) -> Router<(), Body> {
"/v1/chains/:chain_id/revelations/:sequence",
get(revelation),
)
.route("/v1/chains/configs", get(get_chain_configs))
.with_state(state)
}

Expand Down
38 changes: 38 additions & 0 deletions apps/fortuna/src/api/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::{
api::{ApiState, RestError},
config::Config,
};
use axum::{extract::State, Json};

#[derive(serde::Serialize)]
pub struct ChainConfigSummary {
pub name: String,
pub contract_addr: String,
pub reveal_delay_blocks: u64,
pub gas_limit: u32,
pub fee: u128,
}

pub async fn get_chain_configs(
State(_state): State<ApiState>,
) -> anyhow::Result<Json<Vec<ChainConfigSummary>>, RestError> {
let yaml_content = std::fs::read_to_string("config.yaml").map_err(|e| {
tracing::error!("Failed to read config file: {}", e);
RestError::Unknown
})?;
let config: Config = serde_yaml::from_str(&yaml_content).map_err(|e| {
tracing::error!("Failed to parse config file: {}", e);
RestError::Unknown
})?;
let mut configs = Vec::new();
for (name, chain) in config.chains.iter() {
configs.push(ChainConfigSummary {
name: name.clone(),
contract_addr: format!("0x{:x}", chain.contract_addr),
reveal_delay_blocks: chain.reveal_delay_blocks,
gas_limit: chain.gas_limit,
fee: chain.fee,
});
}
Ok(Json(configs))
}
2 changes: 1 addition & 1 deletion apps/fortuna/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub async fn run_api(

pub async fn run(opts: &RunOptions) -> Result<()> {
// Load environment variables from a .env file if present
let _ = dotenv::dotenv()?;
let _ = dotenv::dotenv().map_err(|e| anyhow!("Failed to load .env file: {}", e))?;
let config = Config::load(&opts.config.config)?;
let secret = config.provider.secret.load()?.ok_or(anyhow!(
"Please specify a provider secret in the config file."
Expand Down