feat: wire chain clients into AppState (feature-gated)

Add ChainClients (infra/chains.rs): per-chain data-source handles built once at
startup from config and shared via AppState. Each client is present only when
its chain feature flag is on, and a malformed chain endpoint now fails startup
(fail-closed) rather than the first request. Cloneable (grin's session state is
shared via Arc) so it lives in the cloneable AppState.

Foundation for the wallet-handlers phase — handlers will read these clients
from State. No endpoints yet (openapi unchanged).
This commit is contained in:
jwinterm
2026-06-23 10:39:25 -04:00
parent e2beb17dda
commit b7e3199200
5 changed files with 65 additions and 2 deletions
+4 -1
View File
@@ -9,7 +9,8 @@ use std::sync::Arc;
use sqlx::postgres::PgPoolOptions;
use smirk_backend_core::{
build_router, config::Config, core::session::SessionManager, infra::db::Database, AppState,
build_router, config::Config, core::session::SessionManager, infra::chains::ChainClients,
infra::db::Database, AppState,
};
#[tokio::main]
@@ -33,12 +34,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
config.secrets.ip_salt.clone(),
);
let sessions = SessionManager::new(&config.auth.jwt_secret, config.auth.jwt_expiry_hours);
let chains = ChainClients::from_config(&config)?;
let addr = format!("{}:{}", config.server_host, config.server_port);
let state = Arc::new(AppState {
config,
db,
sessions,
chains,
web_challenges: Arc::default(),
});