pub use solana_tpu_client::nonblocking::tpu_client::{LeaderTpuService, TpuSenderError};
use {
solana_connection_cache::connection_cache::{
ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool,
NewConnectionConfig,
},
solana_message::Message,
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::nonblocking::rpc_client::RpcClient,
solana_signer::signers::Signers,
solana_tpu_client::{
nonblocking::tpu_client::{Result, TpuClient as BackendTpuClient},
tpu_client::TpuClientConfig,
},
solana_transaction::{Transaction, versioned::VersionedTransaction},
solana_transaction_error::{TransactionError, TransportResult},
std::sync::Arc,
};
pub struct TpuClient<
P, M, C, > {
tpu_client: BackendTpuClient<P, M, C>,
}
impl<P, M, C> TpuClient<P, M, C>
where
P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{
pub async fn send_transaction(&self, transaction: &Transaction) -> bool {
self.tpu_client.send_transaction(transaction).await
}
pub async fn send_wire_transaction(&self, wire_transaction: Vec<u8>) -> bool {
self.tpu_client
.send_wire_transaction(wire_transaction)
.await
}
pub async fn try_send_transaction(
&self,
transaction: &VersionedTransaction,
) -> TransportResult<()> {
self.tpu_client.try_send_transaction(transaction).await
}
pub async fn try_send_wire_transaction(
&self,
wire_transaction: Vec<u8>,
) -> TransportResult<()> {
self.tpu_client
.try_send_wire_transaction(wire_transaction)
.await
}
pub async fn try_send_wire_transaction_batch(
&self,
wire_transactions: Vec<Vec<u8>>,
) -> TransportResult<()> {
self.tpu_client
.try_send_wire_transaction_batch(wire_transactions)
.await
}
}
impl TpuClient<QuicPool, QuicConnectionManager, QuicConfig> {
pub async fn new(
name: &'static str,
rpc_client: Arc<RpcClient>,
websocket_url: &str,
config: TpuClientConfig,
) -> Result<Self> {
let connection_manager = QuicConnectionManager::new_with_connection_config(
QuicConfig::new().expect("QUIC client config must be constructible"),
);
Ok(Self {
tpu_client: BackendTpuClient::new(
name,
rpc_client,
websocket_url,
config,
connection_manager,
)
.await?,
})
}
}
impl<P, M, C> TpuClient<P, M, C>
where
P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{
pub async fn new_with_connection_cache(
rpc_client: Arc<RpcClient>,
websocket_url: &str,
config: TpuClientConfig,
connection_cache: Arc<BackendConnectionCache<P, M, C>>,
) -> Result<Self> {
Ok(Self {
tpu_client: BackendTpuClient::new_with_connection_cache(
rpc_client,
websocket_url,
config,
connection_cache,
)
.await?,
})
}
#[deprecated(
since = "4.3.0",
note = "prefer send_and_confirm_transactions_in_parallel_v3"
)]
pub async fn send_and_confirm_messages_with_spinner<T: Signers + ?Sized>(
&self,
messages: &[Message],
signers: &T,
) -> Result<Vec<Option<TransactionError>>> {
#[allow(deprecated)]
self.tpu_client
.send_and_confirm_messages_with_spinner(messages, signers)
.await
}
pub fn rpc_client(&self) -> &RpcClient {
self.tpu_client.rpc_client()
}
pub async fn shutdown(&mut self) {
self.tpu_client.shutdown().await
}
}