taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

lib.rs (1957B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2025, 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 use std::sync::Arc;
     18 
     19 use sqlx::PgPool;
     20 use taler_api::api::{Router, TalerRouter as _};
     21 use taler_common::config::Config;
     22 
     23 use crate::{api::CyclosApi, config::ServeCfg};
     24 
     25 pub mod api;
     26 pub mod config;
     27 pub mod constants;
     28 pub mod cyclos_api;
     29 pub mod db;
     30 pub mod dev;
     31 pub mod notification;
     32 pub mod payto;
     33 pub mod setup;
     34 pub mod worker;
     35 pub use crate::constants::CONFIG_SOURCE;
     36 
     37 pub async fn run_serve(cfg: &Config, pool: PgPool) -> anyhow::Result<()> {
     38     let cfg = ServeCfg::parse(cfg)?;
     39     build_router(&cfg, pool)
     40         .await
     41         .serve(&cfg.serve, None)
     42         .await?;
     43     Ok(())
     44 }
     45 
     46 async fn build_router(cfg: &ServeCfg, pool: PgPool) -> Router {
     47     let api = Arc::new(CyclosApi::start(
     48         pool,
     49         cfg.root.clone(),
     50         cfg.payto.clone(),
     51         cfg.currency,
     52     ));
     53     let mut router = Router::new();
     54     if let Some(cfg) = &cfg.wire_gateway {
     55         router = router
     56             .wire_gateway(api.clone(), cfg.auth.method())
     57             .prepared_transfer(api.clone());
     58     }
     59     if let Some(cfg) = &cfg.revenue {
     60         router = router.revenue(api.clone(), cfg.auth.method());
     61     }
     62     if let Some(cfg) = &cfg.observability {
     63         router = router.observability(api, cfg.auth.method());
     64     }
     65     router
     66 }