solana_client/
tpu_client.rsuse {
crate::connection_cache::ConnectionCache,
solana_connection_cache::connection_cache::{
ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool,
NewConnectionConfig,
},
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::rpc_client::RpcClient,
solana_sdk::{
message::Message,
signers::Signers,
transaction::{Transaction, TransactionError},
transport::Result as TransportResult,
},
solana_tpu_client::tpu_client::{Result, TpuClient as BackendTpuClient},
std::sync::Arc,
};
pub use {
crate::nonblocking::tpu_client::TpuSenderError,
solana_tpu_client::tpu_client::{TpuClientConfig, DEFAULT_FANOUT_SLOTS, MAX_FANOUT_SLOTS},
};
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 fn send_transaction(&self, transaction: &Transaction) -> bool {
self.tpu_client.send_transaction(transaction)
}
pub fn send_wire_transaction(&self, wire_transaction: Vec<u8>) -> bool {
self.tpu_client.send_wire_transaction(wire_transaction)
}
pub fn try_send_transaction(&self, transaction: &Transaction) -> TransportResult<()> {
self.tpu_client.try_send_transaction(transaction)
}
pub fn try_send_transaction_batch(&self, transactions: &[Transaction]) -> TransportResult<()> {
self.tpu_client.try_send_transaction_batch(transactions)
}
pub fn try_send_wire_transaction(&self, wire_transaction: Vec<u8>) -> TransportResult<()> {
self.tpu_client.try_send_wire_transaction(wire_transaction)
}
}
impl TpuClient<QuicPool, QuicConnectionManager, QuicConfig> {
pub fn new(
rpc_client: Arc<RpcClient>,
websocket_url: &str,
config: TpuClientConfig,
) -> Result<Self> {
let connection_cache = match ConnectionCache::new("connection_cache_tpu_client") {
ConnectionCache::Quic(cache) => cache,
ConnectionCache::Udp(_) => {
return Err(TpuSenderError::Custom(String::from(
"Invalid default connection cache",
)))
}
};
Self::new_with_connection_cache(rpc_client, websocket_url, config, connection_cache)
}
}
impl<P, M, C> TpuClient<P, M, C>
where
P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{
pub 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,
)?,
})
}
pub fn send_and_confirm_messages_with_spinner<T: Signers + ?Sized>(
&self,
messages: &[Message],
signers: &T,
) -> Result<Vec<Option<TransactionError>>> {
self.tpu_client
.send_and_confirm_messages_with_spinner(messages, signers)
}
pub fn rpc_client(&self) -> &RpcClient {
self.tpu_client.rpc_client()
}
}