2021-07-20 13:49:32 -05:00
|
|
|
//! A transport for RPC calls.
|
|
|
|
|
2021-09-08 18:44:35 -05:00
|
|
|
use {
|
|
|
|
crate::{client_error::Result, rpc_request::RpcRequest},
|
|
|
|
std::time::Duration,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Default, Clone)]
|
|
|
|
pub struct RpcTransportStats {
|
|
|
|
/// Number of RPC requests issued
|
|
|
|
pub request_count: usize,
|
|
|
|
|
|
|
|
/// Total amount of time spent transacting with the RPC server
|
|
|
|
pub elapsed_time: Duration,
|
|
|
|
|
|
|
|
/// Total amount of waiting time due to RPC server rate limiting
|
|
|
|
/// (a subset of `elapsed_time`)
|
|
|
|
pub rate_limited_time: Duration,
|
|
|
|
}
|
2019-03-16 21:51:41 -07:00
|
|
|
|
2021-07-20 13:49:32 -05:00
|
|
|
/// A transport for RPC calls.
|
|
|
|
///
|
|
|
|
/// `RpcSender` implements the underlying transport of requests to, and
|
|
|
|
/// responses from, a Solana node, and is used primarily by [`RpcClient`].
|
|
|
|
///
|
|
|
|
/// It is typically implemented by [`HttpSender`] in production, and
|
|
|
|
/// [`MockSender`] in unit tests.
|
|
|
|
///
|
|
|
|
/// [`RpcClient`]: crate::rpc_client::RpcClient
|
|
|
|
/// [`HttpSender`]: crate::http_sender::HttpSender
|
|
|
|
/// [`MockSender`]: crate::mock_sender::MockSender
|
2020-05-20 19:40:45 -06:00
|
|
|
pub trait RpcSender {
|
2020-05-22 08:53:53 -07:00
|
|
|
fn send(&self, request: RpcRequest, params: serde_json::Value) -> Result<serde_json::Value>;
|
2021-09-08 18:44:35 -05:00
|
|
|
fn get_transport_stats(&self) -> RpcTransportStats;
|
2019-03-16 21:51:41 -07:00
|
|
|
}
|