Skip to content

Commit

Permalink
chore: separate routes into their respective modules
Browse files Browse the repository at this point in the history
  • Loading branch information
elsirion committed Apr 3, 2024
1 parent 6de14f4 commit 8dcc200
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
13 changes: 12 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -29,6 +33,13 @@ pub mod meta;

/// Helper API that exposes the federation modules
pub mod modules;
pub fn get_config_routes() -> Router<AppState> {
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<InviteCode>,
Expand Down
19 changes: 17 additions & 2 deletions src/federation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<AppState> {
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<AppState>,
Expand Down
32 changes: 6 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 8dcc200

Please sign in to comment.