61 lines
2.6 KiB
Rust
61 lines
2.6 KiB
Rust
// file: crates/ksp-app-wallet-desk/src/offchain_runtime.rs
|
|
// version: 1
|
|
|
|
//! Optional composite-selected Off-chain Transport runtime used by Wallet Desk SOL/USD presentation.
|
|
|
|
/// Safe provider-neutral Off-chain Transport runtime retained by Wallet Desk when Config resolution succeeds.
|
|
pub(crate) struct OffchainTransportRuntime {
|
|
resolved: ksp_config_lib::ResolvedOffchainTransportConfig,
|
|
}
|
|
|
|
impl OffchainTransportRuntime {
|
|
/// Returns the generic market-price service built and owned by Config.
|
|
#[must_use]
|
|
pub(crate) const fn service(&self) -> &ksp_offchain_transport_lib::MarketPriceService {
|
|
return self.resolved.service();
|
|
}
|
|
|
|
/// Returns the composite-selected Off-chain Transport profile identifier.
|
|
#[must_use]
|
|
pub(crate) fn profile_id(&self) -> &str {
|
|
return self.resolved.profile_id();
|
|
}
|
|
}
|
|
|
|
/// Resolves the Wallet Desk Off-chain Transport component through Config.
|
|
pub(crate) fn initialize_offchain_transport(management: &ksp_config_lib::ConfigManagement) -> ksp_core_lib::Result<OffchainTransportRuntime> {
|
|
let environment = ksp_config_lib::ConfigEnvironment::load();
|
|
let environment = match environment {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let composite = crate::load_wallet_desk_composite(management);
|
|
let composite = match composite {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let profile = crate::required_composite_component_profile(
|
|
&composite,
|
|
crate::COMPOSITE_COMPONENT_ID_OFFCHAIN_TRANSPORT,
|
|
ksp_config_lib::FILE_ID_STD_OFFCHAIN_TRANSPORT,
|
|
);
|
|
let profile = match profile {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let resolved = management.engine().resolve_offchain_transport_config_profile(&profile, &environment);
|
|
let resolved = match resolved {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let provider_count = resolved.service().registry().len();
|
|
ksp_logging_lib::info!(
|
|
target: crate::TRACING_TARGET,
|
|
domain = crate::TRACING_DOMAIN_OFFCHAIN_TRANSPORT,
|
|
offchain_profile = resolved.profile_id(),
|
|
provider_count,
|
|
"initialized Wallet Desk Off-chain Transport from composite-managed configuration"
|
|
);
|
|
return std::result::Result::Ok(OffchainTransportRuntime { resolved });
|
|
}
|