v0.2.12-pre.008

This commit is contained in:
2026-08-27 14:41:08 +02:00
parent 2042482592
commit f1e365ec97
22 changed files with 631 additions and 129 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/src/app_state.rs
// version: 19
// version: 20
//! Shared backend state owned by the Wallet Desk Tauri application.
@@ -7,6 +7,7 @@
pub(crate) struct AppState {
config_management: ksp_config_lib::ConfigManagement,
logging_runtime: std::sync::Mutex<LoggingRuntimeState>,
offchain_runtime: std::option::Option<crate::OffchainTransportRuntime>,
splash_settings: crate::SplashSettings,
splash_sequence_started: std::sync::atomic::AtomicBool,
transport_runtime: crate::TransportRuntime,
@@ -41,6 +42,20 @@ impl AppState {
return std::result::Result::Err(error);
},
};
let offchain_runtime = crate::initialize_offchain_transport(&config_management);
let offchain_runtime = match offchain_runtime {
std::result::Result::Ok(value) => std::option::Option::Some(value),
std::result::Result::Err(error) => {
ksp_logging_lib::warn!(
target: crate::TRACING_TARGET,
domain = crate::TRACING_DOMAIN_OFFCHAIN_TRANSPORT,
error_domain = error.code().domain(),
error_code = error.code().code(),
"Wallet Desk Off-chain Transport is unavailable; SOL/USD average will be N.A."
);
std::option::Option::None
},
};
let wallet_config_startup = crate::initialize_wallet_config(&config_management);
let wallet_config_startup = match wallet_config_startup {
std::result::Result::Ok(value) => value,
@@ -66,6 +81,7 @@ impl AppState {
fallback_active: logging_startup.fallback_active,
startup_diagnostic: logging_startup.startup_diagnostic,
}),
offchain_runtime,
splash_settings,
splash_sequence_started: std::sync::atomic::AtomicBool::new(false),
transport_runtime,
@@ -1126,8 +1142,10 @@ impl AppState {
std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed),
std::option::Option::None,
);
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_TRANSPORT, wallet_id = context.wallet_id.as_str(), capability = context.capability, transport_profile = self.transport_runtime.profile_id(), transport_role = self.transport_runtime.role().as_str(), "Wallet balance refresh started");
let result = self.transport_runtime.pool().get_balance(self.transport_runtime.role(), &context.pubkey, std::option::Option::Some(&config)).await;
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_TRANSPORT, wallet_id = context.wallet_id.as_str(), capability = context.capability, transport_profile = self.transport_runtime.profile_id(), transport_role = self.transport_runtime.role().as_str(), "Wallet balance and auxiliary SOL/USD refresh started");
let balance_future = self.transport_runtime.pool().get_balance(self.transport_runtime.role(), &context.pubkey, std::option::Option::Some(&config));
let price_future = self.refresh_sol_usd_average();
let (result, sol_usd_average) = tokio::join!(balance_future, price_future);
let result = match result {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
@@ -1147,14 +1165,52 @@ impl AppState {
lamports: lamports.to_string(),
slot: result.context().slot(),
sol: crate::format_lamports_as_sol(lamports),
sol_usd_average,
transport_profile: self.transport_runtime.profile_id().to_owned(),
transport_role: self.transport_runtime.role().as_str().to_owned(),
wallet_id: context.wallet_id.clone(),
};
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_TRANSPORT, wallet_id = context.wallet_id.as_str(), capability = context.capability, lamports, slot = dto.slot, "Wallet balance refresh succeeded");
ksp_logging_lib::info!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_TRANSPORT, wallet_id = context.wallet_id.as_str(), capability = context.capability, lamports, slot = dto.slot, sol_usd_average_available = dto.sol_usd_average.is_some(), "Wallet balance refresh succeeded");
return std::result::Result::Ok(dto);
}
async fn refresh_sol_usd_average(&self) -> std::option::Option<String> {
let runtime = match &self.offchain_runtime {
std::option::Option::Some(value) => value,
std::option::Option::None => return std::option::Option::None,
};
let outcomes = runtime.service().refresh_all().await;
let outcomes = match outcomes {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => {
ksp_logging_lib::warn!(
target: crate::TRACING_TARGET,
domain = crate::TRACING_DOMAIN_OFFCHAIN_TRANSPORT,
offchain_profile = runtime.profile_id(),
error_domain = error.code().domain(),
error_code = error.code().code(),
"Wallet Desk SOL/USD provider refresh failed; average is unavailable"
);
return std::option::Option::None;
},
};
let prices = outcomes
.iter()
.filter_map(|outcome| return outcome.observation().map(|observation| return observation.price()))
.collect::<std::vec::Vec<_>>();
let average = crate::average_sol_usd_prices(prices.as_slice());
ksp_logging_lib::debug!(
target: crate::TRACING_TARGET,
domain = crate::TRACING_DOMAIN_OFFCHAIN_TRANSPORT,
offchain_profile = runtime.profile_id(),
provider_count = outcomes.len(),
observed_provider_count = prices.len(),
average_available = average.is_some(),
"Wallet Desk SOL/USD refresh completed"
);
return average;
}
fn authorized_balance_context(&self) -> ksp_core_lib::Result<WalletBalanceContext> {
let session = self.wallet_session.lock();
let session = match session {