// file: kb-app-demo-desktop/src/tauri.rs // version: 8 //! Tauri runtime assembly and private command wrappers. use tauri::Manager; // rust-rules: trait-import /// Runs the desktop demo application. #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() -> kb_core::Result<()> { let rustls_result = install_default_rustls_provider(); if let std::result::Result::Err(error) = rustls_result { return std::result::Result::Err(error); } let app_state_result = crate::AppState::initialize(); let app_state; if let std::result::Result::Ok(state) = app_state_result { app_state = state; } else if let std::result::Result::Err(error) = app_state_result { return std::result::Result::Err(error); } else { return std::result::Result::Err(kb_core::Error::invalid_state( "application state initialization produced no result", )); } tracing::info!( target: crate::TRACING_TARGET, config_path = app_state.config_path(), active_profile = app_state.active_profile().name.as_str(), logging_routes = app_state.logging_route_count(), configured_profiles = app_state.app_config().profiles.len(), "starting desktop demo application" ); let tracing_builder = tauri_plugin_tracing::Builder::new(); let mut builder = tauri::Builder::default(); builder = builder.manage(app_state); builder = builder.invoke_handler(tauri::generate_handler![ emit_frontend_log, load_project_readme, open_demo_backfill_window, demo_backfill_options, demo_backfill_execute, demo_backfill_cancel, open_demo_http_window, demo_http_list_pool_clients, demo_http_options, demo_http_execute_request, open_demo_ws_window, demo_ws_list_pool_clients, demo_ws_options, demo_ws_status, demo_ws_connect, demo_ws_unsubscribe, demo_ws_disconnect, open_demo_sql_diag_window, load_demo_sql_diag, open_demo_sql_pg_raw_window, load_demo_sql_pg_raw, open_demo_sql_pg_core_window, load_demo_sql_pg_core, open_demo_sql_replay_candidates_window, demo_sql_replay_options, load_demo_sql_replay_transactions, load_demo_sql_replay_programs, load_demo_sql_replay_entities, export_demo_sql_replay_csv, open_demo_config_window, load_demo_config, ]); builder = builder.plugin(tracing_builder.build::()); builder = builder.setup(|app| { let splash_window = match app.get_webview_window("splash") { std::option::Option::Some(window) => window, std::option::Option::None => { return std::result::Result::Err(std::boxed::Box::new(std::io::Error::new( std::io::ErrorKind::NotFound, "splash window is missing", ))); }, }; let main_window = match app.get_webview_window("main") { std::option::Option::Some(window) => window, std::option::Option::None => { return std::result::Result::Err(std::boxed::Box::new(std::io::Error::new( std::io::ErrorKind::NotFound, "main window is missing", ))); }, }; tauri::async_runtime::spawn(async move { let started_at = tokio::time::Instant::now(); crate::emit_splash_order( &splash_window, "add_log", std::option::Option::Some("Configuration chargée"), std::option::Option::None, std::option::Option::None, ); crate::emit_splash_order( &splash_window, "add_log", std::option::Option::Some("Sous-système de logs initialisé"), std::option::Option::None, std::option::Option::None, ); crate::emit_splash_order( &splash_window, "add_log", std::option::Option::Some("Pool HTTP initialisé"), std::option::Option::None, std::option::Option::None, ); crate::emit_splash_order( &splash_window, "fadein", std::option::Option::None, std::option::Option::None, std::option::Option::Some(crate::SPLASH_FADE_MS), ); crate::emit_splash_order( &splash_window, "add_msg", std::option::Option::Some("Initialisation..."), std::option::Option::Some("info"), std::option::Option::None, ); crate::emit_splash_order( &splash_window, "add_msg", std::option::Option::Some("Loading complete..."), std::option::Option::Some("success"), std::option::Option::None, ); crate::wait_until_minimum(started_at, crate::SPLASH_MINIMUM_MS).await; if cfg!(debug_assertions) { crate::emit_splash_order( &splash_window, "add_log", std::option::Option::Some("Start Fade-out"), std::option::Option::None, std::option::Option::None, ); } crate::emit_splash_order( &splash_window, "fadeout", std::option::Option::None, std::option::Option::None, std::option::Option::Some(crate::SPLASH_FADE_MS), ); tokio::time::sleep(std::time::Duration::from_millis(crate::SPLASH_CLOSE_WAIT_MS)).await; if let std::result::Result::Err(error) = splash_window.destroy() { tracing::error!(target: crate::TRACING_TARGET, "cannot destroy splash window: {error:?}"); } if let std::result::Result::Err(error) = main_window.show() { tracing::error!(target: crate::TRACING_TARGET, "cannot show main window: {error:?}"); } if let std::result::Result::Err(error) = main_window.set_focus() { tracing::error!(target: crate::TRACING_TARGET, "cannot focus main window: {error:?}"); } }); return std::result::Result::Ok(()); }); let run_result = builder.run(tauri::generate_context!()); return match run_result { std::result::Result::Ok(()) => std::result::Result::Ok(()), std::result::Result::Err(error) => std::result::Result::Err(kb_core::Error::tauri(format!( "cannot run desktop demo application: {error:?}" ))), }; } fn install_default_rustls_provider() -> kb_core::Result<()> { if rustls::crypto::CryptoProvider::get_default().is_some() { return std::result::Result::Ok(()); } let provider_result = rustls::crypto::aws_lc_rs::default_provider().install_default(); return match provider_result { std::result::Result::Ok(()) => std::result::Result::Ok(()), std::result::Result::Err(error) => std::result::Result::Err(kb_core::Error::invalid_state( format!("cannot install default rustls crypto provider: {error:?}"), )), }; } #[tauri::command] fn open_demo_config_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { if let std::option::Option::Some(window) = app_handle.get_webview_window("demo_config") { if let std::result::Result::Err(error) = window.show() { return std::result::Result::Err(error.to_string()); } if let std::result::Result::Err(error) = window.set_focus() { return std::result::Result::Err(error.to_string()); } return std::result::Result::Ok(()); } let builder = tauri::WebviewWindowBuilder::new( &app_handle, "demo_config", tauri::WebviewUrl::App("demo_config.html".into()), ) .title("Khadhroony Bot3 - Configuration") .inner_size(1280.0, 820.0) .min_inner_size(960.0, 640.0); let window = match builder.build() { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => { return std::result::Result::Err(error.to_string()); }, }; if let std::result::Result::Err(error) = window.set_focus() { return std::result::Result::Err(error.to_string()); } return std::result::Result::Ok(()); } #[tauri::command] fn load_demo_config( state: tauri::State<'_, crate::AppState>, ) -> crate::DemoConfigPayload { return crate::demo_config_payload(state.inner()); } fn into_ipc_result( result: kb_core::Result, ) -> std::result::Result { return match result { std::result::Result::Ok(value) => std::result::Result::Ok(value), std::result::Result::Err(error) => std::result::Result::Err(error.to_string()), }; } #[tauri::command] fn emit_frontend_log(payload: crate::FrontendLogPayload) { crate::emit_frontend_log(payload); } #[tauri::command] fn load_project_readme() -> std::result::Result { return into_ipc_result(crate::load_project_readme()); } #[tauri::command] fn demo_backfill_cancel(state: tauri::State<'_, crate::AppState>) -> bool { let running = state .demo_backfill_running() .load(std::sync::atomic::Ordering::Acquire); state .demo_backfill_cancel_requested() .store(true, std::sync::atomic::Ordering::Release); return running; } #[tauri::command] fn open_demo_backfill_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { let existing_window = app_handle.get_webview_window("demo_backfill"); if let std::option::Option::Some(window) = existing_window { if let std::result::Result::Err(error) = window.show() { return std::result::Result::Err(error.to_string()); } if let std::result::Result::Err(error) = window.set_focus() { return std::result::Result::Err(error.to_string()); } return std::result::Result::Ok(()); } let build_result = tauri::WebviewWindowBuilder::new( &app_handle, "demo_backfill", tauri::WebviewUrl::App("demo_backfill.html".into()), ) .title("Khadhroony Bot3 - Backfill HTTP") .inner_size(1280.0, 860.0) .min_inner_size(960.0, 620.0) .resizable(true) .visible(true) .build(); return match build_result { std::result::Result::Ok(window) => match window.set_focus() { std::result::Result::Ok(()) => std::result::Result::Ok(()), std::result::Result::Err(error) => std::result::Result::Err(error.to_string()), }, std::result::Result::Err(error) => std::result::Result::Err(error.to_string()), }; } #[tauri::command] fn demo_backfill_options( state: tauri::State<'_, crate::AppState>, ) -> crate::DemoBackfillOptionsPayload { let roles = crate::build_role_options(state.http_pool().snapshot()); let default_role = if roles.iter().any(|item| return item.role == "history_backfill") { std::option::Option::Some("history_backfill".to_string()) } else { roles.first().map(|item| return item.role.clone()) }; return crate::DemoBackfillOptionsPayload { roles, default_role, default_commitment: "confirmed".to_string(), default_page_size: 100, default_max_pages: 20, default_max_concurrent_requests: 4, default_max_retries: 2, running: state .demo_backfill_running() .load(std::sync::atomic::Ordering::Acquire), }; } #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_backfill_execute( app_handle: tauri::AppHandle, state: tauri::State<'_, crate::AppState>, request: crate::DemoBackfillRequest, ) -> std::result::Result { let acquire_result = state.demo_backfill_running().compare_exchange( false, true, std::sync::atomic::Ordering::AcqRel, std::sync::atomic::Ordering::Acquire, ); if acquire_result.is_err() { return std::result::Result::Err("a backfill campaign is already running".to_string()); } let _run_guard = crate::DemoBackfillRunGuard { running: state.demo_backfill_running(), }; state .demo_backfill_cancel_requested() .store(false, std::sync::atomic::Ordering::Release); let pipeline_request = match crate::build_demo_backfill_pipeline_request(request) { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let profile = state.active_profile(); let store_options = match kb_store::PostgresStoreOptions::new( profile.database.postgres.url.clone(), profile.database.postgres.max_connections, profile.database.postgres.connect_timeout_ms, false, ) { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let store = match kb_store::PostgresStore::connect(store_options).await { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; if let std::result::Result::Err(error) = store.initialize_store_schema().await { return std::result::Result::Err(error.to_string()); } let observer = crate::DemoBackfillObserver { app_handle, cancel_requested: state.demo_backfill_cancel_requested(), }; let summary = match kb_pipeline::execute_http_backfill( state.http_pool(), &store, &pipeline_request, &observer, ) .await { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; return std::result::Result::Ok(crate::demo_backfill_summary_payload(summary)); } #[tauri::command] fn open_demo_http_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { let existing_window = app_handle.get_webview_window("demo_http"); if let std::option::Option::Some(window) = existing_window { if let std::result::Result::Err(error) = window.show() { return std::result::Result::Err(error.to_string()); } if let std::result::Result::Err(error) = window.set_focus() { return std::result::Result::Err(error.to_string()); } return std::result::Result::Ok(()); } let build_result = tauri::WebviewWindowBuilder::new( &app_handle, "demo_http", tauri::WebviewUrl::App("demo_http.html".into()), ) .title("Khadhroony Bot3 - HTTP JSON-RPC") .inner_size(1280.0, 860.0) .min_inner_size(960.0, 620.0) .resizable(true) .visible(true) .build(); return match build_result { std::result::Result::Ok(window) => match window.set_focus() { std::result::Result::Ok(()) => std::result::Result::Ok(()), std::result::Result::Err(error) => std::result::Result::Err(error.to_string()), }, std::result::Result::Err(error) => std::result::Result::Err(error.to_string()), }; } #[tauri::command] fn demo_http_list_pool_clients( state: tauri::State<'_, crate::AppState>, ) -> std::vec::Vec { return state.http_pool().snapshot(); } #[tauri::command] fn demo_http_options( state: tauri::State<'_, crate::AppState>, ) -> crate::DemoHttpOptionsPayload { return crate::DemoHttpOptionsPayload { roles: crate::build_http_role_options(state.http_pool().snapshot()), methods: crate::build_http_method_options(), }; } #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_http_execute_request( state: tauri::State<'_, crate::AppState>, request: crate::DemoHttpRequest, ) -> std::result::Result { return crate::demo_http_execute_request_inner(state, request).await; } /// Opens or focuses the WebSocket demo window. #[tauri::command] fn open_demo_ws_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { tracing::info!(target: crate::TRACING_TARGET, "open_demo_ws_window"); if let std::option::Option::Some(window) = app_handle.get_webview_window("demo_ws") { if let std::result::Result::Err(error) = window.show() { return std::result::Result::Err( kb_core::Error::tauri(format!("cannot show demo_ws window: {error}")).to_string(), ); } if let std::result::Result::Err(error) = window.set_focus() { return std::result::Result::Err( kb_core::Error::tauri(format!("cannot focus demo_ws window: {error}")).to_string(), ); } return std::result::Result::Ok(()); } let build_result = tauri::WebviewWindowBuilder::new( &app_handle, "demo_ws", tauri::WebviewUrl::App("demo_ws.html".into()), ) .title("Khadhroony Bot3 - WebSocket standard") .inner_size(1200.0, 760.0) .min_inner_size(920.0, 560.0) .resizable(true) .visible(true) .build(); return match build_result { std::result::Result::Ok(window) => match window.set_focus() { std::result::Result::Ok(()) => std::result::Result::Ok(()), std::result::Result::Err(error) => std::result::Result::Err( kb_core::Error::tauri(format!("cannot focus created demo_ws window: {error}")) .to_string(), ), }, std::result::Result::Err(error) => std::result::Result::Err( kb_core::Error::tauri(format!("cannot create demo_ws window: {error}")).to_string(), ), }; } /// Lists WebSocket endpoints available through the configured pool. #[tauri::command] fn demo_ws_list_pool_clients( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result, std::string::String> { let pool = match state.demo_ws_pool() { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; return std::result::Result::Ok(pool.snapshot()); } /// Lists selectable WebSocket roles and methods for the demo UI. #[tauri::command] fn demo_ws_options( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { return std::result::Result::Ok(crate::DemoWsOptionsPayload { roles: crate::build_ws_role_options(match state.demo_ws_pool() { std::result::Result::Ok(pool) => pool.snapshot(), std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }), methods: crate::build_ws_method_options(), }); } /// Returns the current WebSocket demo session status. #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_ws_status( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { return crate::demo_ws_status_inner(state.inner()).await; } /// Connects if needed, then subscribes through `kb_onchain_transport::WsSession`. #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_ws_connect( app_handle: tauri::AppHandle, state: tauri::State<'_, crate::AppState>, request: crate::DemoWsRequest, ) -> std::result::Result { return crate::demo_ws_connect_inner(app_handle, state.inner(), request).await; } /// Unsubscribes one subscription while keeping the WebSocket connection open. #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_ws_unsubscribe( app_handle: tauri::AppHandle, state: tauri::State<'_, crate::AppState>, request: crate::DemoWsUnsubscribeRequest, ) -> std::result::Result { return crate::demo_ws_unsubscribe_inner(app_handle, state.inner(), request.subscription_id) .await; } /// Disconnects the current persistent WebSocket demo session. #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_ws_disconnect( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { return crate::demo_ws_disconnect_inner(state.inner()).await; } /// Opens or focuses the SQL diagnostic demo window. #[tauri::command] fn open_demo_sql_diag_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { return crate::open_sql_demo_window( app_handle, "demo_sql_diag", "demo_sql_diag.html", "Khadhroony Bot3 - SQL diagnostics", ); } /// Loads read-only SQL diagnostics from the active profile. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_diag( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { let profile = state.active_profile().clone(); let store_result = crate::connect_postgres_store(&profile).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let diagnostics_result = store.backend_diagnostics().await; let diagnostics = match diagnostics_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let tables_result = store.known_table_diagnostics().await; let tables = match tables_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; return std::result::Result::Ok(crate::DemoSqlDiagPayload { config_path: state.config_path().to_string(), active_profile_name: profile.name.clone(), backend: profile.database.backend.clone(), masked_dsn: store.options().masked_dsn(), current_schema: diagnostics.descriptor.current_schema, health_status: crate::debug_status(diagnostics.health.status), health_message: diagnostics.health.message, migration_status: crate::debug_status(diagnostics.migrations.status), migration_message: diagnostics.migrations.message, server_version: diagnostics.server_version, tables: crate::table_snapshots_from_pg(tables.as_slice()), }); } /// Opens or focuses the PostgreSQL canonical acquisition demo window. #[tauri::command] fn open_demo_sql_pg_raw_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { return crate::open_sql_demo_window( app_handle, "demo_sql_pg_raw", "demo_sql_pg_raw.html", "Khadhroony Bot3 - PostgreSQL canonical acquisition", ); } /// Loads read-only raw table diagnostics from PostgreSQL. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_pg_raw( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { let profile = state.active_profile().clone(); let store_result = crate::connect_postgres_store(&profile).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let tables_result = store.raw_table_diagnostics().await; let tables = match tables_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; return std::result::Result::Ok(crate::DemoSqlPgRawPayload { active_profile_name: profile.name.clone(), masked_dsn: store.options().masked_dsn(), tables: crate::table_snapshots_from_pg(tables.as_slice()), }); } /// Opens or focuses the PostgreSQL core store demo window. #[tauri::command] fn open_demo_sql_pg_core_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { return crate::open_sql_demo_window( app_handle, "demo_sql_pg_core", "demo_sql_pg_core.html", "Khadhroony Bot3 - PostgreSQL core store", ); } /// Loads read-only core table diagnostics from PostgreSQL. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_pg_core( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { let profile = state.active_profile().clone(); let store_result = crate::connect_postgres_store(&profile).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let tables_result = store.core_table_diagnostics().await; let tables = match tables_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; return std::result::Result::Ok(crate::DemoSqlPgCorePayload { active_profile_name: profile.name.clone(), masked_dsn: store.options().masked_dsn(), tables: crate::table_snapshots_from_pg(tables.as_slice()), }); } /// Opens or focuses the SQL replay candidate browser. #[tauri::command] fn open_demo_sql_replay_candidates_window( app_handle: tauri::AppHandle, ) -> std::result::Result<(), std::string::String> { return crate::open_sql_demo_window( app_handle, "demo_sql_replay_candidates", "demo_sql_replay_candidates.html", "Khadhroony Bot3 - SQL replay candidates", ); } /// Writes a bounded replay-candidate CSV file into `./data/exports_csv/`. #[tauri::command] #[allow(clippy::question_mark_used)] async fn export_demo_sql_replay_csv( file_name: std::string::String, content: std::string::String, ) -> std::result::Result { if content.is_empty() { return std::result::Result::Err("CSV export content must not be empty".to_owned()); } if content.len() > 16 * 1024 * 1024 { return std::result::Result::Err("CSV export content exceeds 16 MiB".to_owned()); } let normalized_name_result = crate::validated_csv_file_name(&file_name); let normalized_name = match normalized_name_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let current_dir_result = std::env::current_dir(); let current_dir = match current_dir_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => { return std::result::Result::Err(format!("cannot resolve current directory: {error}")); }, }; let export_dir = crate::csv_export_directory_from_current_dir(¤t_dir); let create_result = tokio::fs::create_dir_all(&export_dir).await; if let std::result::Result::Err(error) = create_result { return std::result::Result::Err(format!("cannot create CSV export directory: {error}")); } let export_path_result = crate::available_csv_export_path(&export_dir, normalized_name).await; let export_path = match export_path_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let mut bytes = std::vec::Vec::with_capacity(content.len() + 3); bytes.extend_from_slice(&[0xEF, 0xBB, 0xBF]); bytes.extend_from_slice(content.as_bytes()); let write_result = tokio::fs::write(&export_path, bytes).await; if let std::result::Result::Err(error) = write_result { return std::result::Result::Err(format!("cannot write CSV export: {error}")); } let display_path = export_path.to_string_lossy().into_owned(); tracing::info!(target: crate::TRACING_TARGET, path = %display_path, "CSV replay candidate export written"); return std::result::Result::Ok(display_path); } /// Loads static browser options from the active PostgreSQL profile. #[tauri::command] #[allow(clippy::question_mark_used)] async fn demo_sql_replay_options( state: tauri::State<'_, crate::AppState>, ) -> std::result::Result { let profile = state.active_profile().clone(); let options_result = crate::postgres_store_options_from_profile(&profile, false); let options = match options_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let mut known_programs = std::vec::Vec::with_capacity(kb_program_ids::registered_program_ids().len()); for entry in kb_program_ids::registered_program_ids() { known_programs.push(crate::DemoSqlReplayKnownProgramOption { code: entry.code().to_owned(), program_id: entry.program_id().to_owned(), }); } return std::result::Result::Ok(crate::DemoSqlReplayOptionsPayload { active_profile_name: profile.name, masked_dsn: options.masked_dsn(), maximum_limit: kb_store::MAX_REPLAY_CANDIDATE_ROWS, known_programs, }); } /// Loads bounded transaction replay candidates from PostgreSQL. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_replay_transactions( state: tauri::State<'_, crate::AppState>, request: crate::DemoSqlReplayTransactionRequest, ) -> std::result::Result, std::string::String> { let program_scope_result = crate::program_scope_from_code(request.program_scope.as_str()); let program_scope = match program_scope_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let entity_kind_result = crate::optional_entity_kind_from_code(request.entity_kind.as_deref()); let entity_kind = match entity_kind_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let filter_result = kb_store::PostgresReplayTransactionFilter::new( request.signature_contains, request.min_slot, request.max_slot, request.raw_processing_state, request.ledger_status, request.program_id, program_scope, entity_kind, request.entity_value, request.limit, request.newest_first, ); let filter = match filter_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let store_result = crate::connect_postgres_store(state.active_profile()).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let rows_result = store.replay_transaction_candidates(&filter).await; let rows = match rows_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; tracing::debug!(target: crate::TRACING_TARGET, rows = rows.len(), "loaded replay transaction candidates"); let mut output = std::vec::Vec::with_capacity(rows.len()); for row in rows { output.push(crate::transaction_row_from_pg(row)); } return std::result::Result::Ok(output); } /// Loads bounded program summaries from PostgreSQL. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_replay_programs( state: tauri::State<'_, crate::AppState>, request: crate::DemoSqlReplayProgramRequest, ) -> std::result::Result, std::string::String> { let filter_result = kb_store::PostgresReplayProgramFilter::new(request.program_id_contains, request.limit); let filter = match filter_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let store_result = crate::connect_postgres_store(state.active_profile()).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let rows_result = store.replay_program_summaries(&filter).await; let rows = match rows_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; tracing::debug!(target: crate::TRACING_TARGET, rows = rows.len(), "loaded replay program summaries"); let mut output = std::vec::Vec::with_capacity(rows.len()); for row in rows { output.push(crate::program_row_from_pg(row)); } return std::result::Result::Ok(output); } /// Loads bounded mint, owner or account-key summaries from PostgreSQL core tables. #[tauri::command] #[allow(clippy::question_mark_used)] async fn load_demo_sql_replay_entities( state: tauri::State<'_, crate::AppState>, request: crate::DemoSqlReplayEntityRequest, ) -> std::result::Result, std::string::String> { let entity_kind_result = crate::entity_kind_from_code(request.entity_kind.as_str()); let entity_kind = match entity_kind_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let filter_result = kb_store::PostgresReplayEntityFilter::new( entity_kind, request.entity_value_contains, request.limit, ); let filter = match filter_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; let store_result = crate::connect_postgres_store(state.active_profile()).await; let store = match store_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let rows_result = store.replay_entity_summaries(&filter).await; let rows = match rows_result { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()), }; tracing::debug!(target: crate::TRACING_TARGET, rows = rows.len(), "loaded replay entity summaries"); let mut output = std::vec::Vec::with_capacity(rows.len()); for row in rows { output.push(crate::entity_row_from_pg(row)); } return std::result::Result::Ok(output); }