v0.2.3-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/src/rpc_transactions.rs
|
||||
// version: 4
|
||||
// version: 5
|
||||
|
||||
/// Binary encoding accepted for serialized transaction input payloads.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
@@ -20,7 +20,6 @@ impl SolanaTransactionBinaryEncoding {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn from_wire(value: &str) -> std::option::Option<Self> {
|
||||
return match value {
|
||||
"base58" => std::option::Option::Some(Self::Base58),
|
||||
@@ -167,7 +166,6 @@ impl SolanaGetTransactionConfig {
|
||||
|
||||
/// Serializes the modern config to its 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 {
|
||||
@@ -827,7 +825,6 @@ pub enum SolanaEncodedTransaction {
|
||||
|
||||
impl SolanaEncodedTransaction {
|
||||
/// Decodes the untagged transaction wire union without decoding transaction bytes.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
return match value {
|
||||
serde_json::Value::String(data) => std::result::Result::Ok(Self::LegacyBinary(data)),
|
||||
@@ -848,7 +845,6 @@ pub enum SolanaTransactionVersion {
|
||||
}
|
||||
|
||||
impl SolanaTransactionVersion {
|
||||
#[cfg(test)]
|
||||
fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
return match value {
|
||||
serde_json::Value::String(value) if value == "legacy" => std::result::Result::Ok(Self::Legacy),
|
||||
@@ -926,7 +922,6 @@ impl SolanaConfirmedTransaction {
|
||||
}
|
||||
|
||||
/// Decodes one non-null confirmed transaction without decoding Program-specific transaction internals.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireConfirmedTransaction>(method, value);
|
||||
let wire = match decoded {
|
||||
@@ -1251,6 +1246,74 @@ impl crate::HttpTransportPool {
|
||||
};
|
||||
}
|
||||
|
||||
/// Executes the current object-form `getTransaction` 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 `{}` object when the
|
||||
/// caller explicitly supplies an empty modern configuration object.
|
||||
pub async fn get_transaction(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
signature: &str,
|
||||
config: std::option::Option<&crate::SolanaGetTransactionConfig>,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedTransaction>> {
|
||||
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,
|
||||
"getTransaction commitment must be confirmed or finalized when explicitly provided",
|
||||
)
|
||||
.with_context("rpc_method", "getTransaction")
|
||||
.with_context("commitment", "processed"),
|
||||
);
|
||||
}
|
||||
let mut params = std::vec![serde_json::Value::String(signature.to_owned())];
|
||||
if let std::option::Option::Some(config) = config {
|
||||
params.push((*config).to_json_value());
|
||||
}
|
||||
return self.execute_get_transaction(role, params).await;
|
||||
}
|
||||
|
||||
/// Executes the deprecated bare-encoding `getTransaction` request form retained by Solana RPC for backwards compatibility.
|
||||
#[deprecated(note = "use HttpTransportPool::get_transaction with SolanaGetTransactionConfig; the bare encoding request form is deprecated")]
|
||||
pub async fn get_transaction_legacy(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
signature: &str,
|
||||
encoding: crate::SolanaTransactionEncoding,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedTransaction>> {
|
||||
ksp_logging_lib::warn!(
|
||||
target: crate::TRACING_TARGET,
|
||||
rpc_method = "getTransaction",
|
||||
request_form = "bare_encoding",
|
||||
encoding = encoding.as_str(),
|
||||
"deprecated Solana HTTP RPC request form used"
|
||||
);
|
||||
let params = std::vec![serde_json::Value::String(signature.to_owned()), serde_json::Value::String(encoding.as_str().to_owned()),];
|
||||
return self.execute_get_transaction(role, params).await;
|
||||
}
|
||||
|
||||
async fn execute_get_transaction(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
params: std::vec::Vec<serde_json::Value>,
|
||||
) -> ksp_core_lib::Result<std::option::Option<crate::SolanaConfirmedTransaction>> {
|
||||
let value = self.execute_transaction_rpc("getTransaction", 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 transaction = crate::SolanaConfirmedTransaction::decode_wire("getTransaction", value);
|
||||
return match transaction {
|
||||
std::result::Result::Ok(transaction) => std::result::Result::Ok(std::option::Option::Some(transaction)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Executes typed `getTransactionCount` through the common KSP HTTP transport path.
|
||||
pub async fn get_transaction_count(
|
||||
&self,
|
||||
@@ -1450,7 +1513,6 @@ fn decode_confirmation_status(
|
||||
return std::result::Result::Ok(std::option::Option::Some(status));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_binary_transaction_tuple(method: &str, values: std::vec::Vec<serde_json::Value>) -> ksp_core_lib::Result<crate::SolanaEncodedTransaction> {
|
||||
if values.len() != 2 {
|
||||
return std::result::Result::Err(invalid_transaction_wire(method, "transaction", "encoded transaction tuple must contain data and encoding"));
|
||||
@@ -1490,7 +1552,6 @@ fn decode_binary_transaction_tuple(method: &str, values: std::vec::Vec<serde_jso
|
||||
return std::result::Result::Ok(crate::SolanaEncodedTransaction::Binary { data, encoding });
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn decode_transaction_version_field(
|
||||
method: &str,
|
||||
field: crate::SolanaWireField<serde_json::Value>,
|
||||
@@ -1597,7 +1658,6 @@ struct WireSignatureStatus {
|
||||
confirmation_status: std::option::Option<std::string::String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireConfirmedTransaction {
|
||||
|
||||
Reference in New Issue
Block a user