gemachain_client/
rpc_sender.rs

1//! A transport for RPC calls.
2
3use {
4    crate::{client_error::Result, rpc_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 Gemachain node, and is used primarily by [`RpcClient`].
25///
26/// It is typically implemented by [`HttpSender`] in production, and
27/// [`MockSender`] in unit tests.
28///
29/// [`RpcClient`]: crate::rpc_client::RpcClient
30/// [`HttpSender`]: crate::http_sender::HttpSender
31/// [`MockSender`]: crate::mock_sender::MockSender
32pub trait RpcSender {
33    fn send(&self, request: RpcRequest, params: serde_json::Value) -> Result<serde_json::Value>;
34    fn get_transport_stats(&self) -> RpcTransportStats;
35}