This commit is contained in:
2026-04-17 19:18:34 +02:00
parent d6a33a7fcb
commit 09838c4dd7
10 changed files with 454 additions and 28 deletions

View File

@@ -1,12 +1,8 @@
// file: khbb_lib/src/app.rs
//! Application bootstrap for khbb binaries.
/// Runs the initial listener application workflow.
///
/// This first version only:
/// - loads configuration
/// - opens the SQLite connection pool
/// - verifies connectivity
/// - keeps the runtime alive as the future integration point for listener tasks
pub async fn run_listener_app(config_path: &str) -> core::result::Result<(), crate::KhbbError> {
let config_result = crate::KhbbAppConfig::load_from_json_file(config_path).await;
let config = match config_result {
@@ -27,21 +23,28 @@ pub async fn run_listener_app(config_path: &str) -> core::result::Result<(), cra
solana_http_rpc_url = %config.solana_http_rpc_url,
solana_ws_rpc_url = %config.solana_ws_rpc_url,
yellowstone_grpc_url = ?config.yellowstone_grpc_url,
bootstrap_database = config.bootstrap_database,
listener_poll_interval_ms = config.listener_poll_interval_ms,
"khbb listener app starting"
);
let connect_result = sqlx::sqlite::SqlitePoolOptions::new()
.max_connections(1)
.connect(&config.database_url)
.await;
let pool = match connect_result {
let pool_result = crate::create_sqlite_pool(&config.database_url).await;
let pool = match pool_result {
Ok(value) => value,
Err(error) => {
return Err(crate::KhbbError::Database {
context: "connect sqlite pool",
message: error.to_string(),
});
return Err(error);
},
};
if config.bootstrap_database {
let schema_result = crate::ensure_sqlite_schema(&pool).await;
match schema_result {
Ok(()) => {
tracing::info!("sqlite schema bootstrap succeeded");
},
Err(error) => {
return Err(error);
},
}
}
let ping_result = sqlx::query("SELECT 1;").execute(&pool).await;
match ping_result {
Ok(_) => {
@@ -54,6 +57,9 @@ pub async fn run_listener_app(config_path: &str) -> core::result::Result<(), cra
});
},
}
tracing::info!("listener tasks are not wired yet");
Ok(())
let listener_result = crate::run_listener_runtime(&pool, &config).await;
match listener_result {
Ok(()) => Ok(()),
Err(error) => Err(error),
}
}