Skip to content

Commit ba15827

Browse files
committed
chore(fortuna) Config API
1 parent d62a045 commit ba15827

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

apps/fortuna/src/api.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use {
2222
tokio::sync::RwLock,
2323
url::Url,
2424
};
25-
pub use {chain_ids::*, explorer::*, index::*, live::*, metrics::*, ready::*, revelation::*};
25+
pub use {chain_ids::*, config::*, explorer::*, index::*, live::*, metrics::*, ready::*, revelation::*};
2626

2727
mod chain_ids;
2828
mod explorer;
@@ -31,6 +31,7 @@ mod live;
3131
mod metrics;
3232
mod ready;
3333
mod revelation;
34+
mod config;
3435

3536
pub type ChainId = String;
3637
pub type NetworkId = u64;
@@ -211,6 +212,7 @@ pub fn routes(state: ApiState) -> Router<(), Body> {
211212
"/v1/chains/:chain_id/revelations/:sequence",
212213
get(revelation),
213214
)
215+
.route("/v1/chains/configs", get(get_chain_configs))
214216
.with_state(state)
215217
}
216218

apps/fortuna/src/api/config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::{api::{ApiState, RestError}, config::Config};
2+
use axum::{extract::State, Json};
3+
4+
#[derive(serde::Serialize)]
5+
pub struct ChainConfigSummary {
6+
pub name: String,
7+
pub contract_addr: String,
8+
pub reveal_delay_blocks: u64,
9+
pub gas_limit: u32,
10+
pub fee: u128,
11+
}
12+
13+
pub async fn get_chain_configs(State(_state): State<ApiState>) -> Result<Json<Vec<ChainConfigSummary>>, RestError> {
14+
// Try to load the config file (assume default path for now)
15+
let config = match Config::load("config.yaml") {
16+
Ok(cfg) => cfg,
17+
Err(_) => return Err(RestError::Unknown),
18+
};
19+
let mut configs = Vec::new();
20+
for (name, chain) in config.chains.iter() {
21+
configs.push(ChainConfigSummary {
22+
name: name.clone(),
23+
contract_addr: format!("0x{:x}", chain.contract_addr),
24+
reveal_delay_blocks: chain.reveal_delay_blocks,
25+
gas_limit: chain.gas_limit,
26+
fee: chain.fee,
27+
});
28+
}
29+
Ok(Json(configs))
30+
}

0 commit comments

Comments
 (0)