70 lines
2.4 KiB
Rust
70 lines
2.4 KiB
Rust
// file: khbb_lib/src/app.rs
|
|
|
|
//! Application bootstrap for khbb binaries.
|
|
|
|
/// Runs the initial listener application workflow.
|
|
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 {
|
|
Ok(value) => value,
|
|
Err(error) => {
|
|
return Err(error);
|
|
},
|
|
};
|
|
let tracing_result = crate::init_tracing(&config.log_filter);
|
|
match tracing_result {
|
|
Ok(()) => {},
|
|
Err(error) => {
|
|
return Err(error);
|
|
},
|
|
}
|
|
tracing::info!(
|
|
database_url = %config.database_url,
|
|
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,
|
|
enable_ws_slot_subscribe = config.enable_ws_slot_subscribe,
|
|
enable_ws_logs_subscribe = config.enable_ws_logs_subscribe,
|
|
enable_ws_program_subscribe = config.enable_ws_program_subscribe,
|
|
ws_program_subscribe_program_ids = ?config.ws_program_subscribe_program_ids,
|
|
"khbb listener app starting"
|
|
);
|
|
let pool_result = crate::create_sqlite_pool(&config.database_url).await;
|
|
let pool = match pool_result {
|
|
Ok(value) => value,
|
|
Err(error) => {
|
|
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(_) => {
|
|
tracing::info!("sqlite connectivity check succeeded");
|
|
},
|
|
Err(error) => {
|
|
return Err(crate::KhbbError::Database {
|
|
context: "ping sqlite database",
|
|
message: error.to_string(),
|
|
});
|
|
},
|
|
}
|
|
let listener_result = crate::run_listener_runtime(&pool, &config).await;
|
|
match listener_result {
|
|
Ok(()) => Ok(()),
|
|
Err(error) => Err(error),
|
|
}
|
|
}
|