Skip to content

Commit

Permalink
fix(transports): fix wasm compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iskorotkov committed Jan 4, 2025
1 parent 596b561 commit f8d1ac9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0.39"
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
pin-project = "1.0"
async-recursion = "1.0.5"
chrono = "0.4.31"
# Optional deps
secp256k1 = { version = "0.28", features = ["recovery"], optional = true }
Expand Down
84 changes: 42 additions & 42 deletions src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
error::{Error, RateLimit, Result, TransportError},
helpers, BatchTransport, RequestId, Transport,
};
use async_recursion::async_recursion;
use chrono::{DateTime, Utc};
use core::time::Duration;
#[cfg(not(feature = "wasm"))]
Expand Down Expand Up @@ -166,57 +165,58 @@ fn extract_retry_after_value(headers: &HeaderMap) -> DelayAfter {
DelayAfter::Date(header.to_string())
}

#[async_recursion]
async fn execute_rpc_with_retries<T: DeserializeOwned + std::marker::Send>(
client: &Client,
fn execute_rpc_with_retries<'a, T: DeserializeOwned + std::marker::Send>(
client: &'a Client,
url: Url,
request: &Request,
request: &'a Request,
id: RequestId,
retries: Retries,
) -> Result<T> {
match execute_rpc(client, url.clone(), request, id).await {
Ok(output) => Ok(output),
Err(Error::Transport(error)) => match error {
TransportError::Code(code) => {
if retries.max_retries <= 0
|| retries.sleep_for <= Duration::from_secs(0)
|| (code != 429 && code < 500)
{
return Err(Error::Transport(error));
}
) -> BoxFuture<'a, Result<T>> {
Box::pin(async move {
match execute_rpc(client, url.clone(), request, id).await {
Ok(output) => Ok(output),
Err(Error::Transport(error)) => match error {
TransportError::Code(code) => {
if retries.max_retries <= 0
|| retries.sleep_for <= Duration::from_secs(0)
|| (code != 429 && code < 500)
{
return Err(Error::Transport(error));
}

Delay::new(retries.sleep_for).await;
execute_rpc_with_retries(client, url, request, id, retries.step()).await
}
TransportError::Message(message) => Err(Error::Transport(TransportError::Message(message))),
TransportError::RateLimit(limit) => {
if !retries.use_retry_after_header && retries.max_retries <= 0 {
return Err(Error::Transport(TransportError::Code(429)));
Delay::new(retries.sleep_for).await;
execute_rpc_with_retries(client, url, request, id, retries.step()).await
}
TransportError::Message(message) => Err(Error::Transport(TransportError::Message(message))),
TransportError::RateLimit(limit) => {
if !retries.use_retry_after_header && retries.max_retries <= 0 {
return Err(Error::Transport(TransportError::Code(429)));
}

match limit {
RateLimit::Date(date) => {
let Ok(until) = DateTime::parse_from_rfc2822(&date) else {
return Err(Error::Transport(TransportError::Code(429)));
};
match limit {
RateLimit::Date(date) => {
let Ok(until) = DateTime::parse_from_rfc2822(&date) else {
return Err(Error::Transport(TransportError::Code(429)));
};

let from_now = until.with_timezone(&Utc::now().timezone()) - Utc::now();
let secs = from_now.num_seconds() + 1; // +1 for rounding
if secs > 0 {
Delay::new(Duration::from_secs(secs as u64)).await;
}
let from_now = until.with_timezone(&Utc::now().timezone()) - Utc::now();
let secs = from_now.num_seconds() + 1; // +1 for rounding
if secs > 0 {
Delay::new(Duration::from_secs(secs as u64)).await;
}

execute_rpc_with_retries(client, url, request, id, retries.step()).await
}
RateLimit::Seconds(seconds) => {
Delay::new(Duration::from_secs(seconds)).await;
execute_rpc_with_retries(client, url, request, id, retries.step()).await
execute_rpc_with_retries(client, url, request, id, retries.step()).await
}
RateLimit::Seconds(seconds) => {
Delay::new(Duration::from_secs(seconds)).await;
execute_rpc_with_retries(client, url, request, id, retries.step()).await
}
}
}
}
},
Err(err) => Err(err),
}
},
Err(err) => Err(err),
}
})
}

type RpcResult = Result<Value>;
Expand Down

0 comments on commit f8d1ac9

Please sign in to comment.