solana_rpc_client/rpc_sender.rs
1//! A transport for RPC calls.
2use {
3 async_trait::async_trait,
4 solana_rpc_client_api::{client_error::Result, request::RpcRequest},
5 std::time::Duration,
6};
7
8#[derive(Default, Clone)]
9pub struct RpcTransportStats {
10 /// Number of RPC requests issued
11 pub request_count: usize,
12
13 /// Total amount of time spent transacting with the RPC server
14 pub elapsed_time: Duration,
15
16 /// Total amount of waiting time due to RPC server rate limiting
17 /// (a subset of `elapsed_time`)
18 pub rate_limited_time: Duration,
19}
20
21/// A transport for RPC calls.
22///
23/// `RpcSender` implements the underlying transport of requests to, and
24/// responses from, a Solana node, and is used primarily by [`RpcClient`].
25///
26/// [`RpcClient`]: crate::rpc_client::RpcClient
27#[async_trait]
28pub trait RpcSender {
29 async fn send(
30 &self,
31 request: RpcRequest,
32 params: serde_json::Value,
33 ) -> Result<serde_json::Value>;
34 fn get_transport_stats(&self) -> RpcTransportStats;
35 fn url(&self) -> String;
36}