consolidates quic/udp dispatch macros (#30249)
This commit is contained in:
parent
6558c8fdc9
commit
6d566889ef
|
@ -145,17 +145,30 @@ impl Default for ConnectionCache {
|
|||
}
|
||||
|
||||
macro_rules! dispatch {
|
||||
($vis:vis fn $name:ident(&self $(, $arg:ident : $ty:ty)?) $(-> $out:ty)?) => {
|
||||
($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident),*>)?(&self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$vis fn $name(&self $(, $arg:$ty)?) $(-> $out)? {
|
||||
$(#[$meta])*
|
||||
$vis fn $name$(<$($t: $cons),*>)?(&self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => this.$name($($arg, )?),
|
||||
Self::Udp(this) => this.$name($($arg, )?),
|
||||
Self::Quic(this) => this.$name($($arg, )*),
|
||||
Self::Udp(this) => this.$name($($arg, )*),
|
||||
}
|
||||
}
|
||||
};
|
||||
($(#[$meta:meta])* $vis:vis fn $name:ident$(<$($t:ident: $cons:ident),*>)?(&mut self $(, $arg:ident: $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$(#[$meta])*
|
||||
$vis fn $name$(<$($t: $cons),*>)?(&mut self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => this.$name($($arg, )*),
|
||||
Self::Udp(this) => this.$name($($arg, )*),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use dispatch;
|
||||
|
||||
impl ClientConnection for BlockingClientConnection {
|
||||
dispatch!(fn server_addr(&self) -> &SocketAddr);
|
||||
dispatch!(fn send_data(&self, buffer: &[u8]) -> TransportResult<()>);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! unstable and may change in future releases.
|
||||
|
||||
use {
|
||||
crate::connection_cache::ConnectionCache,
|
||||
crate::connection_cache::{dispatch, ConnectionCache},
|
||||
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
|
||||
solana_rpc_client::rpc_client::RpcClient,
|
||||
solana_rpc_client_api::config::RpcProgramAccountsConfig,
|
||||
|
@ -37,61 +37,6 @@ pub enum ThinClient {
|
|||
Udp(BackendThinClient<UdpPool, UdpConnectionManager, UdpConfig>),
|
||||
}
|
||||
|
||||
/// Macros easing the forwarding calls to the BackendThinClient
|
||||
macro_rules! dispatch {
|
||||
/* Regular version */
|
||||
($vis:vis fn $name:ident(&self $(, $arg:ident : $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$vis fn $name(&self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => this.$name($($arg),*),
|
||||
Self::Udp(this) => this.$name($($arg),*),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* The self is a mut */
|
||||
($vis:vis fn $name:ident(&mut self $(, $arg:ident : $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$vis fn $name(&mut self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => this.$name($($arg),*),
|
||||
Self::Udp(this) => this.$name($($arg),*),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* There is a type parameter */
|
||||
($vis:vis fn $name:ident<T: Signers>(&self $(, $arg:ident : $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$vis fn $name<T: Signers>(&self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => this.$name($($arg),*),
|
||||
Self::Udp(this) => this.$name($($arg),*),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Macro forwarding calls to BackendThinClient with deprecated functions
|
||||
macro_rules! dispatch_allow_deprecated {
|
||||
($vis:vis fn $name:ident(&self $(, $arg:ident : $ty:ty)*) $(-> $out:ty)?) => {
|
||||
#[inline]
|
||||
$vis fn $name(&self $(, $arg:$ty)*) $(-> $out)? {
|
||||
match self {
|
||||
Self::Quic(this) => {
|
||||
#[allow(deprecated)]
|
||||
this.$name($($arg),*)
|
||||
}
|
||||
Self::Udp(this) => {
|
||||
#[allow(deprecated)]
|
||||
this.$name($($arg),*)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl ThinClient {
|
||||
/// Create a new ThinClient that will interface with the Rpc at `rpc_addr` using TCP
|
||||
/// and the Tpu at `tpu_addr` over `transactions_socket` using Quic or UDP
|
||||
|
@ -266,19 +211,19 @@ impl SyncClient for ThinClient {
|
|||
|
||||
dispatch!(fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> TransportResult<u64>);
|
||||
|
||||
dispatch_allow_deprecated!(fn get_recent_blockhash(&self) -> TransportResult<(Hash, FeeCalculator)>);
|
||||
dispatch!(#[allow(deprecated)] fn get_recent_blockhash(&self) -> TransportResult<(Hash, FeeCalculator)>);
|
||||
|
||||
dispatch_allow_deprecated!(fn get_recent_blockhash_with_commitment(
|
||||
dispatch!(#[allow(deprecated)] fn get_recent_blockhash_with_commitment(
|
||||
&self,
|
||||
commitment_config: CommitmentConfig
|
||||
) -> TransportResult<(Hash, FeeCalculator, Slot)>);
|
||||
|
||||
dispatch_allow_deprecated!(fn get_fee_calculator_for_blockhash(
|
||||
dispatch!(#[allow(deprecated)] fn get_fee_calculator_for_blockhash(
|
||||
&self,
|
||||
blockhash: &Hash
|
||||
) -> TransportResult<Option<FeeCalculator>>);
|
||||
|
||||
dispatch_allow_deprecated!(fn get_fee_rate_governor(&self) -> TransportResult<FeeRateGovernor>);
|
||||
dispatch!(#[allow(deprecated)] fn get_fee_rate_governor(&self) -> TransportResult<FeeRateGovernor>);
|
||||
|
||||
dispatch!(fn get_signature_status(
|
||||
&self,
|
||||
|
@ -315,7 +260,7 @@ impl SyncClient for ThinClient {
|
|||
|
||||
dispatch!(fn poll_for_signature(&self, signature: &Signature) -> TransportResult<()>);
|
||||
|
||||
dispatch_allow_deprecated!(fn get_new_blockhash(&self, blockhash: &Hash) -> TransportResult<(Hash, FeeCalculator)>);
|
||||
dispatch!(#[allow(deprecated)] fn get_new_blockhash(&self, blockhash: &Hash) -> TransportResult<(Hash, FeeCalculator)>);
|
||||
|
||||
dispatch!(fn get_latest_blockhash(&self) -> TransportResult<Hash>);
|
||||
|
||||
|
|
Loading…
Reference in New Issue