pub struct HttpTransportClient {
pub client: Arc<Client>,
/* private fields */
}
Expand description
Basic HTTP transport client for blockchain interactions
This client provides a foundation for making JSON-RPC requests to blockchain nodes with built-in support for:
- Connection pooling and reuse
- Automatic endpoint rotation on failure
- Configurable retry policies
The client is thread-safe and can be shared across multiple tasks.
Fields§
§client: Arc<Client>
HTTP client for making requests, wrapped in Arc for thread-safety
Implementations§
Source§impl HttpTransportClient
impl HttpTransportClient
Sourcepub async fn new(
network: &Network,
test_connection_payload: Option<String>,
) -> Result<Self, Error>
pub async fn new( network: &Network, test_connection_payload: Option<String>, ) -> Result<Self, Error>
Creates a new HTTP transport client with automatic endpoint management
This constructor attempts to connect to available endpoints in order of their weight until a successful connection is established. It configures default timeout and retry policies suitable for blockchain interactions.
§Arguments
network
- Network configuration containing RPC URLs, weights, and other detailstest_connection_payload
- Optional JSON RPC payload to test the connection (default is net_version)
§Returns
Result<Self, anyhow::Error>
- New client instance or connection error
Trait Implementations§
Source§impl BlockchainTransport for HttpTransportClient
impl BlockchainTransport for HttpTransportClient
Source§fn get_current_url<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_current_url<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieves the currently active RPC endpoint URL
This method is useful for monitoring which endpoint is currently in use, especially in scenarios with multiple failover URLs.
§Returns
String
- The URL of the currently active endpoint
Source§fn send_raw_request<'life0, 'life1, 'async_trait, P>(
&'life0 self,
method: &'life1 str,
params: Option<P>,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>
fn send_raw_request<'life0, 'life1, 'async_trait, P>( &'life0 self, method: &'life1 str, params: Option<P>, ) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>
Sends a JSON-RPC request to the blockchain node
This method handles the formatting of the JSON-RPC request, including:
- Adding required JSON-RPC 2.0 fields
- Generating unique request IDs
- Converting parameters to the correct format
- Handling authentication
§Arguments
method
- The JSON-RPC method name to callparams
- Optional parameters for the method call
§Returns
Result<Value, anyhow::Error>
- JSON response or error with context
§Type Parameters
P
- Parameter type that can be serialized to JSON
Source§fn set_retry_policy(
&mut self,
retry_policy: ExponentialBackoff,
retry_strategy: Option<TransientErrorRetryStrategy>,
) -> Result<(), Error>
fn set_retry_policy( &mut self, retry_policy: ExponentialBackoff, retry_strategy: Option<TransientErrorRetryStrategy>, ) -> Result<(), Error>
Source§fn update_endpoint_manager_client(
&mut self,
client: ClientWithMiddleware,
) -> Result<(), Error>
fn update_endpoint_manager_client( &mut self, client: ClientWithMiddleware, ) -> Result<(), Error>
Update endpoint manager with a new client
§Arguments
client
- The new client to use for the endpoint manager
Source§impl Clone for HttpTransportClient
impl Clone for HttpTransportClient
Source§fn clone(&self) -> HttpTransportClient
fn clone(&self) -> HttpTransportClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for HttpTransportClient
impl Debug for HttpTransportClient
Source§impl RotatingTransport for HttpTransportClient
impl RotatingTransport for HttpTransportClient
Source§fn try_connect<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn try_connect<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for HttpTransportClient
impl !RefUnwindSafe for HttpTransportClient
impl Send for HttpTransportClient
impl Sync for HttpTransportClient
impl Unpin for HttpTransportClient
impl !UnwindSafe for HttpTransportClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more