v0.2.8-pre.002

This commit is contained in:
2026-08-23 13:15:42 +02:00
parent 315e7e67e5
commit 0871b85df9
12 changed files with 767 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/ws_session.rs
// version: 12
// version: 13
use futures_util::SinkExt; // rust-rules: trait-import
use futures_util::StreamExt; // rust-rules: trait-import
@@ -24,15 +24,32 @@ pub struct WsSession {
}
impl WsSession {
/// Opens one physical WebSocket connection for the supplied endpoint settings.
/// Opens one physical standard Solana WebSocket connection for the supplied endpoint settings.
///
/// Calling this function twice with the same endpoint creates two independent physical sessions. The function returns only after the WebSocket
/// handshake succeeds or the configured command timeout expires.
/// This historical constructor remains standard-only after provider-specific protocol kinds are added. Calling this function twice with the same endpoint
/// creates two independent physical sessions. Provider-specific callers must use their typed protocol facade instead of obtaining a generic handle.
pub async fn connect(endpoint: crate::WsEndpointSettings) -> ksp_core_lib::Result<Self> {
return Self::connect_for_protocol(endpoint, crate::WsProtocolKind::SolanaStandard).await;
}
/// Opens one physical WebSocket connection after validating the typed facade protocol.
pub(crate) async fn connect_for_protocol(endpoint: crate::WsEndpointSettings, expected_protocol: crate::WsProtocolKind) -> ksp_core_lib::Result<Self> {
let validation = crate::WsTransportSettings::new(std::vec![endpoint.clone()]).validate();
if let std::result::Result::Err(error) = validation {
return std::result::Result::Err(error);
}
if endpoint.protocol() != expected_protocol {
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_SETTINGS, "WebSocket session constructor does not accept the endpoint protocol")
.with_context("field", "ws_endpoints.protocol")
.with_context("expected_protocol", expected_protocol.as_str())
.with_context("actual_protocol", endpoint.protocol().as_str()),
);
}
return Self::connect_physical(endpoint).await;
}
async fn connect_physical(endpoint: crate::WsEndpointSettings) -> ksp_core_lib::Result<Self> {
let id_result = next_session_id();
let id = match id_result {
std::result::Result::Ok(id) => id,