v0.2.4-pre.006
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/src/rpc_blocks.rs
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
/// Transaction detail level accepted by modern `getBlock` requests.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
|
||||
@@ -93,7 +93,6 @@ impl SolanaGetBlockConfig {
|
||||
|
||||
/// Serializes this config to the exact Solana JSON-RPC 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 {
|
||||
@@ -354,7 +353,6 @@ impl SolanaBlockReward {
|
||||
return &self.commission_bps;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireBlockReward>(method, value);
|
||||
let wire = match decoded {
|
||||
@@ -403,7 +401,6 @@ impl SolanaBlockTransaction {
|
||||
return &self.version;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireBlockTransaction>(method, value);
|
||||
let wire = match decoded {
|
||||
@@ -493,7 +490,6 @@ impl SolanaConfirmedBlock {
|
||||
}
|
||||
|
||||
/// Decodes a confirmed block from its 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::<WireConfirmedBlock>(method, value);
|
||||
let wire = match decoded {
|
||||
@@ -582,6 +578,74 @@ impl SolanaPerformanceSample {
|
||||
}
|
||||
|
||||
impl crate::HttpTransportPool {
|
||||
/// Executes the current object-form `getBlock` request through the common KSP HTTP transport path.
|
||||
///
|
||||
/// `None` omits the optional second parameter. `Some(config)` sends the modern object form exactly, including an empty `{}` when the caller
|
||||
/// explicitly supplies an empty modern configuration. The runtime requires an explicitly supplied commitment to be at least `confirmed`.
|
||||
pub async fn get_block(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
slot: u64,
|
||||
config: std::option::Option<&crate::SolanaGetBlockConfig>,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedBlock>> {
|
||||
if let std::option::Option::Some(config) = config
|
||||
&& config.commitment() == std::option::Option::Some(crate::SolanaCommitment::Processed)
|
||||
{
|
||||
return std::result::Result::Err(
|
||||
ksp_core_lib::Error::new(
|
||||
crate::ERROR_CODE_INVALID_RPC_PARAMETERS,
|
||||
"getBlock commitment must be confirmed or finalized when explicitly provided",
|
||||
)
|
||||
.with_context("rpc_method", "getBlock")
|
||||
.with_context("commitment", "processed"),
|
||||
);
|
||||
}
|
||||
let mut params = std::vec![serde_json::json!(slot)];
|
||||
if let std::option::Option::Some(config) = config {
|
||||
params.push((*config).to_json_value());
|
||||
}
|
||||
return self.execute_get_block(role, params).await;
|
||||
}
|
||||
|
||||
/// Executes the deprecated bare-encoding `getBlock` request form retained by Solana RPC for backwards compatibility.
|
||||
#[deprecated(note = "use HttpTransportPool::get_block with SolanaGetBlockConfig; the bare encoding request form is deprecated")]
|
||||
pub async fn get_block_legacy(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
slot: u64,
|
||||
encoding: crate::SolanaTransactionEncoding,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedBlock>> {
|
||||
ksp_logging_lib::warn!(
|
||||
target: crate::TRACING_TARGET,
|
||||
rpc_method = "getBlock",
|
||||
request_form = "bare_encoding",
|
||||
encoding = encoding.as_str(),
|
||||
"deprecated Solana HTTP RPC request form used"
|
||||
);
|
||||
let params = std::vec![serde_json::json!(slot), serde_json::Value::String(encoding.as_str().to_owned())];
|
||||
return self.execute_get_block(role, params).await;
|
||||
}
|
||||
|
||||
async fn execute_get_block(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
params: std::vec::Vec<serde_json::Value>,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedBlock>> {
|
||||
let value = self.execute_blocks_rpc("getBlock", role, params).await;
|
||||
let value = match value {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
if value.is_null() {
|
||||
return std::result::Result::Ok(std::option::Option::None);
|
||||
}
|
||||
let block = crate::SolanaConfirmedBlock::decode_wire("getBlock", value);
|
||||
return match block {
|
||||
std::result::Result::Ok(block) => std::result::Result::Ok(std::option::Option::Some(block)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Executes typed `getBlockCommitment` through the common KSP HTTP transport path.
|
||||
pub async fn get_block_commitment(&self, role: &crate::HttpRoleName, slot: u64) -> ksp_core_lib::Result<crate::SolanaBlockCommitment> {
|
||||
let value = self.execute_blocks_rpc("getBlockCommitment", role, std::vec![serde_json::json!(slot)]).await;
|
||||
@@ -857,7 +921,6 @@ fn blocks_descriptor(method: &str) -> ksp_core_lib::Result<&'static crate::HttpR
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_block_transaction_version(
|
||||
method: &str,
|
||||
field: crate::SolanaWireField<serde_json::Value>,
|
||||
@@ -875,7 +938,6 @@ fn decode_block_transaction_version(
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_block_transactions(
|
||||
method: &str,
|
||||
field: crate::SolanaWireField<std::vec::Vec<serde_json::Value>>,
|
||||
@@ -896,7 +958,6 @@ fn decode_block_transactions(
|
||||
return std::result::Result::Ok(crate::SolanaWireField::Value(transactions));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_block_rewards(
|
||||
method: &str,
|
||||
field: crate::SolanaWireField<std::vec::Vec<serde_json::Value>>,
|
||||
@@ -944,7 +1005,6 @@ struct WireBlockProductionRpcResponse {
|
||||
value: serde_json::Value,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireBlockReward {
|
||||
@@ -959,7 +1019,6 @@ struct WireBlockReward {
|
||||
commission_bps: crate::SolanaWireField<u16>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireBlockTransaction {
|
||||
@@ -970,7 +1029,6 @@ struct WireBlockTransaction {
|
||||
version: crate::SolanaWireField<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireConfirmedBlock {
|
||||
|
||||
Reference in New Issue
Block a user