v0.2.2-pre.002-fix.001

This commit is contained in:
2026-08-18 07:17:49 +02:00
parent e68f073505
commit f625ee5979
12 changed files with 606 additions and 137 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/rpc_common.rs
// version: 1
// version: 2
/// Commitment level accepted by typed Solana HTTP RPC adapters.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@@ -43,15 +43,10 @@ impl SolanaCommitmentConfig {
return self.commitment;
}
/// Returns whether this config serializes to an empty JSON object.
#[must_use]
pub(crate) const fn is_empty(&self) -> bool {
return self.commitment.is_none();
}
/// Serializes this config to the Solana JSON-RPC wire object.
#[must_use]
pub(crate) fn to_json_value(&self) -> serde_json::Value {
#[cfg(test)]
pub(crate) fn to_json_value(self) -> serde_json::Value {
let mut object = serde_json::Map::new();
if let std::option::Option::Some(commitment) = self.commitment {
object.insert("commitment".to_owned(), serde_json::Value::String(commitment.as_str().to_owned()));
@@ -86,15 +81,9 @@ impl SolanaContextConfig {
return self.min_context_slot;
}
/// Returns whether this config serializes to an empty JSON object.
#[must_use]
pub(crate) const fn is_empty(&self) -> bool {
return self.commitment.is_none() && self.min_context_slot.is_none();
}
/// Serializes this config to the Solana JSON-RPC wire object.
#[must_use]
pub(crate) fn to_json_value(&self) -> serde_json::Value {
pub(crate) fn to_json_value(self) -> serde_json::Value {
let mut object = serde_json::Map::new();
if let std::option::Option::Some(commitment) = self.commitment {
object.insert("commitment".to_owned(), serde_json::Value::String(commitment.as_str().to_owned()));
@@ -129,7 +118,8 @@ impl SolanaRpcContext {
};
}
/// Decodes one RPC context from a parsed JSON value.
/// Decodes one RPC context from a parsed JSON value for staged DTO tests.
#[cfg(test)]
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireRpcContext>(method, value);
let context = match decoded {
@@ -160,7 +150,8 @@ impl<T> SolanaRpcResponse<T> {
return &self.value;
}
/// Creates a contextual response after wire decoding and validation.
/// Creates a contextual response after wire decoding and validation for staged DTO tests.
#[cfg(test)]
#[must_use]
pub(crate) const fn new(context: crate::SolanaRpcContext, value: T) -> Self {
return Self { context, value };
@@ -168,6 +159,7 @@ impl<T> SolanaRpcResponse<T> {
}
/// Decodes one private serde wire type and maps shape failures to the shared Transport error domain.
#[cfg(test)]
pub(crate) fn decode_wire_json<T: serde::de::DeserializeOwned>(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<T> {
let decoded = serde_json::from_value::<T>(value);
return match decoded {
@@ -181,6 +173,7 @@ pub(crate) fn decode_wire_json<T: serde::de::DeserializeOwned>(method: &str, val
}
/// Parses a base58 public key from one wire field without echoing its value into diagnostics.
#[cfg(test)]
pub(crate) fn parse_wire_pubkey(method: &str, field: &str, value: &str) -> ksp_core_lib::Result<ksp_core_lib::Pubkey> {
let parsed = value.parse::<ksp_core_lib::Pubkey>();
return match parsed {
@@ -193,6 +186,7 @@ pub(crate) fn parse_wire_pubkey(method: &str, field: &str, value: &str) -> ksp_c
};
}
#[cfg(test)]
#[derive(serde::Deserialize)]
struct WireRpcContext {
slot: u64,