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_accounts.rs
// version: 1
// version: 2
/// Account-data encoding accepted by Solana HTTP account methods.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@@ -29,6 +29,7 @@ impl SolanaAccountEncoding {
};
}
#[cfg(test)]
fn from_wire(value: &str) -> std::option::Option<Self> {
return match value {
"binary" => std::option::Option::Some(Self::Binary),
@@ -67,6 +68,7 @@ impl SolanaDataSliceConfig {
return self.length;
}
#[cfg(test)]
fn to_json_value(self) -> serde_json::Value {
return serde_json::json!({"offset": self.offset, "length": self.length});
}
@@ -116,14 +118,9 @@ impl SolanaAccountInfoConfig {
return self.context.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.encoding.is_none() && self.data_slice.is_none() && self.context.is_empty();
}
/// Serializes this config to the Solana JSON-RPC wire object.
#[must_use]
#[cfg(test)]
pub(crate) fn to_json_value(&self) -> serde_json::Value {
let context_value = self.context.to_json_value();
let mut object = match context_value {
@@ -150,6 +147,7 @@ pub enum SolanaLargestAccountsFilter {
}
impl SolanaLargestAccountsFilter {
#[cfg(test)]
fn as_str(self) -> &'static str {
return match self {
Self::Circulating => "circulating",
@@ -197,6 +195,7 @@ impl SolanaLargestAccountsConfig {
/// Serializes this config to the Solana JSON-RPC wire object.
#[must_use]
#[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 {
@@ -249,6 +248,7 @@ impl SolanaMemcmpFilter {
return &self.bytes;
}
#[cfg(test)]
fn to_json_value(&self) -> serde_json::Value {
return match &self.bytes {
crate::SolanaMemcmpBytes::Base58(bytes) => serde_json::json!({"offset": self.offset, "bytes": bytes, "encoding": "base58"}),
@@ -270,6 +270,7 @@ pub enum SolanaProgramAccountFilter {
}
impl SolanaProgramAccountFilter {
#[cfg(test)]
fn to_json_value(&self) -> serde_json::Value {
return match self {
Self::DataSize(size) => serde_json::json!({"dataSize": size}),
@@ -326,6 +327,7 @@ impl SolanaProgramAccountsConfig {
/// Serializes this config to the Solana JSON-RPC wire object.
#[must_use]
#[cfg(test)]
pub(crate) fn to_json_value(&self) -> serde_json::Value {
let account_value = self.account_config.to_json_value();
let mut object = match account_value {
@@ -391,6 +393,7 @@ pub enum SolanaAccountData {
}
impl SolanaAccountData {
#[cfg(test)]
fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireAccountData>(method, value);
let wire = match decoded {
@@ -399,11 +402,9 @@ impl SolanaAccountData {
};
return match wire {
WireAccountData::LegacyBinary(value) => std::result::Result::Ok(Self::LegacyBinary(value)),
WireAccountData::JsonParsed(value) => std::result::Result::Ok(Self::JsonParsed(crate::SolanaParsedAccountData {
program: value.program,
parsed: value.parsed,
space: value.space,
})),
WireAccountData::JsonParsed(value) => {
std::result::Result::Ok(Self::JsonParsed(crate::SolanaParsedAccountData { program: value.program, parsed: value.parsed, space: value.space }))
},
WireAccountData::Encoded((data, encoding)) => {
let parsed = crate::SolanaAccountEncoding::from_wire(encoding.as_str());
let encoding = match parsed {
@@ -413,7 +414,7 @@ impl SolanaAccountData {
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_RESPONSE, "account data tuple uses an unknown encoding")
.with_context("rpc_method", method),
);
}
},
};
if encoding == crate::SolanaAccountEncoding::Binary || encoding == crate::SolanaAccountEncoding::JsonParsed {
return std::result::Result::Err(
@@ -422,7 +423,7 @@ impl SolanaAccountData {
);
}
std::result::Result::Ok(Self::Encoded { data, encoding })
}
},
};
}
}
@@ -476,6 +477,7 @@ impl SolanaAccount {
}
/// Decodes one account DTO from the Solana JSON wire shape.
#[cfg(test)]
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireAccount>(method, value);
let wire = match decoded {
@@ -524,6 +526,7 @@ impl SolanaKeyedAccount {
}
/// Decodes one keyed account from the Solana JSON wire shape.
#[cfg(test)]
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireKeyedAccount>(method, value);
let wire = match decoded {
@@ -565,6 +568,7 @@ impl SolanaAccountBalance {
}
/// Decodes one account-balance entry from the Solana JSON wire shape.
#[cfg(test)]
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireAccountBalance>(method, value);
let wire = match decoded {
@@ -588,6 +592,7 @@ pub enum SolanaProgramAccountsResult {
Context(crate::SolanaRpcResponse<std::vec::Vec<crate::SolanaKeyedAccount>>),
}
#[cfg(test)]
#[derive(serde::Deserialize)]
#[serde(untagged)]
enum WireAccountData {
@@ -596,6 +601,7 @@ enum WireAccountData {
Encoded((std::string::String, std::string::String)),
}
#[cfg(test)]
#[derive(serde::Deserialize)]
struct WireParsedAccountData {
program: std::string::String,
@@ -603,6 +609,7 @@ struct WireParsedAccountData {
space: u64,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
struct WireAccount {
lamports: u64,
@@ -615,12 +622,14 @@ struct WireAccount {
space: std::option::Option<u64>,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
struct WireKeyedAccount {
pubkey: std::string::String,
account: serde_json::Value,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
struct WireAccountBalance {
address: std::string::String,