diff --git a/src/config/mod.rs b/src/config/mod.rs index 6b0131b..4b8c3a1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -2,7 +2,8 @@ use std::collections::HashMap; use std::sync::Arc; use axum::extract::{Path, State}; -use axum::Json; +use axum::routing::get; +use axum::{Json, Router}; use fedimint_core::api::InviteCode; use fedimint_core::config::{ ClientConfig, ClientModuleConfig, FederationId, JsonClientConfig, JsonWithKind, @@ -18,6 +19,9 @@ use fedimint_mint_common::MintCommonInit; use fedimint_wallet_common::WalletCommonInit; use tracing::warn; +use crate::config::id::fetch_federation_id; +use crate::config::meta::fetch_federation_meta; +use crate::config::modules::fetch_federation_module_kinds; use crate::error::Result; use crate::AppState; @@ -29,6 +33,13 @@ pub mod meta; /// Helper API that exposes the federation modules pub mod modules; +pub fn get_config_routes() -> Router { + Router::new() + .route("/:invite", get(fetch_federation_config)) + .route("/:invite/meta", get(fetch_federation_meta)) + .route("/:invite/id", get(fetch_federation_id)) + .route("/:invite/module_kinds", get(fetch_federation_module_kinds)) +} pub async fn fetch_federation_config( Path(invite): Path, diff --git a/src/federation/mod.rs b/src/federation/mod.rs index fcebe3a..cde2d7c 100644 --- a/src/federation/mod.rs +++ b/src/federation/mod.rs @@ -5,7 +5,8 @@ use std::time::{Duration, SystemTime}; use anyhow::{ensure, Context}; use axum::extract::{Path, State}; -use axum::Json; +use axum::routing::{get, put}; +use axum::{Json, Router}; use axum_auth::AuthBearer; use fedimint_core::api::{DynGlobalApi, InviteCode}; use fedimint_core::config::{ClientConfig, FederationId}; @@ -30,7 +31,21 @@ use tracing::{debug, error}; use crate::config::get_decoders; use crate::federation::db::Federation; -use crate::AppState; +use crate::{federation, AppState}; + +pub fn get_federations_routes() -> Router { + Router::new() + .route("/", get(list_observed_federations)) + .route("/", put(add_observed_federation)) + .route( + "/:federation_id/transactions", + get(list_federation_transactions), + ) + .route( + "/:federation_id/config", + get(federation::get_federation_config), + ) +} pub async fn list_observed_federations( State(state): State, diff --git a/src/main.rs b/src/main.rs index 11e3128..4452270 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,14 @@ use anyhow::Context; -use axum::routing::{get, put}; +use axum::routing::get; use axum::Router; use tracing::info; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::EnvFilter; -use crate::config::id::fetch_federation_id; -use crate::config::meta::{fetch_federation_meta, MetaOverrideCache}; -use crate::config::modules::fetch_federation_module_kinds; -use crate::config::{fetch_federation_config, FederationConfigCache}; -use crate::federation::{ - add_observed_federation, list_federation_transactions, list_observed_federations, - FederationObserver, -}; +use crate::config::meta::MetaOverrideCache; +use crate::config::{get_config_routes, FederationConfigCache}; +use crate::federation::{get_federations_routes, FederationObserver}; /// Fedimint config fetching service implementation mod config; @@ -45,23 +40,8 @@ async fn main() -> anyhow::Result<()> { let app = Router::new() .route("/health", get(|| async { "Server is up and running!" })) - .route("/config/:invite", get(fetch_federation_config)) - .route("/config/:invite/meta", get(fetch_federation_meta)) - .route("/config/:invite/id", get(fetch_federation_id)) - .route( - "/config/:invite/module_kinds", - get(fetch_federation_module_kinds), - ) - .route("/federations", get(list_observed_federations)) - .route("/federations", put(add_observed_federation)) - .route( - "/federations/:federation_id/transactions", - get(list_federation_transactions), - ) - .route( - "/federations/:federation_id/config", - get(federation::get_federation_config), - ) + .nest("/config", get_config_routes()) + .nest("/federations", get_federations_routes()) .with_state(AppState { federation_config_cache: Default::default(), meta_override_cache: Default::default(),