Skip to content

Commit

Permalink
Remove unused RpcClient encoding maping, node_version
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Jul 8, 2024
1 parent ad90698 commit ce1cdbf
Showing 1 changed file with 5 additions and 44 deletions.
49 changes: 5 additions & 44 deletions rpc-client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use {
str::FromStr,
time::{Duration, Instant},
},
tokio::{sync::RwLock, time::sleep},
tokio::time::sleep,
};

/// A client of a remote Solana node.
Expand Down Expand Up @@ -140,7 +140,6 @@ use {
pub struct RpcClient {
sender: Box<dyn RpcSender + Send + Sync + 'static>,
config: RpcClientConfig,
node_version: RwLock<Option<semver::Version>>,
}

impl RpcClient {
Expand All @@ -156,7 +155,6 @@ impl RpcClient {
) -> Self {
Self {
sender: Box::new(sender),
node_version: RwLock::new(None),
config,
}
}
Expand Down Expand Up @@ -508,30 +506,11 @@ impl RpcClient {
self.sender.url()
}

pub async fn set_node_version(&self, version: semver::Version) -> Result<(), ()> {
let mut w_node_version = self.node_version.write().await;
*w_node_version = Some(version);
#[deprecated(since = "2.0.2", note = "RpcClient::node_version is no longer used")]
pub async fn set_node_version(&self, _version: semver::Version) -> Result<(), ()> {
Ok(())
}

async fn get_node_version(&self) -> Result<semver::Version, RpcError> {
let r_node_version = self.node_version.read().await;
if let Some(version) = &*r_node_version {
Ok(version.clone())
} else {
drop(r_node_version);
let mut w_node_version = self.node_version.write().await;
let node_version = self.get_version().await.map_err(|e| {
RpcError::RpcRequestError(format!("cluster version query failed: {e}"))
})?;
let node_version = semver::Version::parse(&node_version.solana_core).map_err(|e| {
RpcError::RpcRequestError(format!("failed to parse cluster version: {e}"))
})?;
*w_node_version = Some(node_version.clone());
Ok(node_version)
}
}

/// Get the configured default [commitment level][cl].
///
/// [cl]: https://solana.com/docs/rpc#configuring-state-commitment
Expand Down Expand Up @@ -883,11 +862,7 @@ impl RpcClient {
transaction: &impl SerializableTransaction,
config: RpcSendTransactionConfig,
) -> ClientResult<Signature> {
let encoding = if let Some(encoding) = config.encoding {
encoding
} else {
self.default_cluster_transaction_encoding().await?
};
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base64);
let preflight_commitment = CommitmentConfig {
commitment: config.preflight_commitment.unwrap_or_default(),
};
Expand Down Expand Up @@ -1173,16 +1148,6 @@ impl RpcClient {
}
}

async fn default_cluster_transaction_encoding(
&self,
) -> Result<UiTransactionEncoding, RpcError> {
if self.get_node_version().await? < semver::Version::new(1, 3, 16) {
Ok(UiTransactionEncoding::Base58)
} else {
Ok(UiTransactionEncoding::Base64)
}
}

/// Simulates sending a transaction.
///
/// If the transaction fails, then the [`err`] field of the returned
Expand Down Expand Up @@ -1332,11 +1297,7 @@ impl RpcClient {
transaction: &impl SerializableTransaction,
config: RpcSimulateTransactionConfig,
) -> RpcResult<RpcSimulateTransactionResult> {
let encoding = if let Some(encoding) = config.encoding {
encoding
} else {
self.default_cluster_transaction_encoding().await?
};
let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Base64);
let commitment = config.commitment.unwrap_or_default();
let config = RpcSimulateTransactionConfig {
encoding: Some(encoding),
Expand Down

0 comments on commit ce1cdbf

Please sign in to comment.