2021-07-20 11:49:32 -07:00
|
|
|
//! A transport for RPC calls.
|
2021-09-08 16:44:35 -07:00
|
|
|
use {
|
2022-01-24 17:01:07 -08:00
|
|
|
async_trait::async_trait,
|
2022-08-23 22:34:35 -07:00
|
|
|
solana_rpc_client_api::{client_error::Result, request::RpcRequest},
|
2021-09-08 16:44:35 -07:00
|
|
|
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 11:49:32 -07: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`].
|
|
|
|
///
|
2022-03-09 20:42:23 -08:00
|
|
|
/// [`RpcClient`]: crate::rpc_client::RpcClient
|
2022-01-24 17:01:07 -08:00
|
|
|
#[async_trait]
|
2022-02-28 10:49:37 -08:00
|
|
|
pub trait RpcSender {
|
2022-01-24 17:01:07 -08:00
|
|
|
async fn send(
|
|
|
|
&self,
|
|
|
|
request: RpcRequest,
|
|
|
|
params: serde_json::Value,
|
|
|
|
) -> Result<serde_json::Value>;
|
2021-09-08 16:44:35 -07:00
|
|
|
fn get_transport_stats(&self) -> RpcTransportStats;
|
2022-04-12 08:43:29 -07:00
|
|
|
fn url(&self) -> String;
|
2019-03-16 21:51:41 -07:00
|
|
|
}
|