feat(provider): add option to create ws provider with auth (#1363)

Currently `Provider::<Ws>` only exposes `connect` from `Ws` module.
This pull request exposes the `connect_with_auth` function added on 829.
This commit is contained in:
Resende 2022-06-09 08:45:33 +01:00 committed by GitHub
parent 295f86ef89
commit c76f325b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -8,7 +8,7 @@ use crate::{
}; };
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use crate::transports::{HttpRateLimitRetryPolicy, RetryClient}; use crate::transports::{Authorization, HttpRateLimitRetryPolicy, RetryClient};
#[cfg(feature = "celo")] #[cfg(feature = "celo")]
use crate::CeloMiddleware; use crate::CeloMiddleware;
@ -1286,6 +1286,15 @@ impl Provider<crate::Ws> {
Ok(Self::new(ws)) Ok(Self::new(ws))
} }
#[cfg(not(target_arch = "wasm32"))]
pub async fn connect_with_auth(
url: impl tokio_tungstenite::tungstenite::client::IntoClientRequest + Unpin,
auth: Authorization,
) -> Result<Self, ProviderError> {
let ws = crate::Ws::connect_with_auth(url, auth).await?;
Ok(Self::new(ws))
}
/// Direct connection to a websocket endpoint /// Direct connection to a websocket endpoint
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
pub async fn connect(url: &str) -> Result<Self, ProviderError> { pub async fn connect(url: &str) -> Result<Self, ProviderError> {