pub struct EndpointManager {
pub active_url: Arc<RwLock<String>>,
pub fallback_urls: Arc<RwLock<Vec<String>>>,
/* private fields */
}
Expand description
Manages the rotation of blockchain RPC endpoints
Provides methods for rotating between multiple URLs and sending requests to the active endpoint with automatic fallback to other URLs on failure.
§Fields
active_url
- The current active URLfallback_urls
- A list of fallback URLs to rotate toclient
- The client to use for the endpoint managerrotation_lock
- A lock for managing the rotation process
Fields§
§active_url: Arc<RwLock<String>>
§fallback_urls: Arc<RwLock<Vec<String>>>
Implementations§
Source§impl EndpointManager
impl EndpointManager
Sourcepub fn new(
client: ClientWithMiddleware,
active_url: &str,
fallback_urls: Vec<String>,
) -> Self
pub fn new( client: ClientWithMiddleware, active_url: &str, fallback_urls: Vec<String>, ) -> Self
Sourcepub fn update_client(&mut self, client: ClientWithMiddleware)
pub fn update_client(&mut self, client: ClientWithMiddleware)
Updates the client with a new client
Useful for updating the client with a new retry policy or strategy
§Arguments
client
- The new client to use for the endpoint manager
Sourcepub fn set_retry_policy<R: RetryableStrategy + Send + Sync + 'static>(
&mut self,
retry_policy: ExponentialBackoff,
retry_strategy: R,
)
pub fn set_retry_policy<R: RetryableStrategy + Send + Sync + 'static>( &mut self, retry_policy: ExponentialBackoff, retry_strategy: R, )
Updates the retry policy for the client
Constructs a new client with the given retry policy and strategy and updates the endpoint manager with the new client
§Arguments
retry_policy
- The new retry policy to use for the clientretry_strategy
- The new retry strategy to use for the client
Sourcepub async fn rotate_url<T: RotatingTransport>(
&self,
transport: &T,
) -> Result<(), Error>
pub async fn rotate_url<T: RotatingTransport>( &self, transport: &T, ) -> Result<(), Error>
Sourcepub async fn send_raw_request<T: RotatingTransport, P: Into<Value> + Send + Clone + Serialize>(
&self,
transport: &T,
method: &str,
params: Option<P>,
) -> Result<Value, Error>
pub async fn send_raw_request<T: RotatingTransport, P: Into<Value> + Send + Clone + Serialize>( &self, transport: &T, method: &str, params: Option<P>, ) -> Result<Value, Error>
Sends a raw request to the blockchain RPC endpoint with automatic URL rotation on failure
§Arguments
transport
- The transport client implementing the RotatingTransport traitmethod
- The RPC method name to callparams
- The parameters for the RPC method call as a JSON Value
§Returns
Result<Value, anyhow::Error>
- The JSON response from the RPC endpoint or an error
§Behavior
- Automatically rotates to fallback URLs if the request fails with specific status codes (e.g., 429)
- Retries the request with the new URL after rotation
- Returns the first successful response or an error if all attempts fail
Trait Implementations§
Source§impl Clone for EndpointManager
impl Clone for EndpointManager
Source§fn clone(&self) -> EndpointManager
fn clone(&self) -> EndpointManager
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for EndpointManager
impl !RefUnwindSafe for EndpointManager
impl Send for EndpointManager
impl Sync for EndpointManager
impl Unpin for EndpointManager
impl !UnwindSafe for EndpointManager
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
Mutably borrows from an owned value. Read more
§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>
Converts
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>
Converts
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