Skip to content

Commit bfec9a8

Browse files
committed
fix(transports): fix wasm compile errors
1 parent f041b22 commit bfec9a8

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ serde = { version = "1.0.90", features = ["derive"] }
2828
serde_json = "1.0.39"
2929
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
3030
pin-project = "1.0"
31-
async-recursion = "1.0.5"
3231
chrono = "0.4.31"
3332
# Optional deps
3433
secp256k1 = { version = "0.28", features = ["recovery"], optional = true }

src/transports/http.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
error::{Error, RateLimit, Result, TransportError},
55
helpers, BatchTransport, RequestId, Transport,
66
};
7-
use async_recursion::async_recursion;
87
use chrono::{DateTime, Utc};
98
use core::time::Duration;
109
#[cfg(not(feature = "wasm"))]
@@ -166,57 +165,58 @@ fn extract_retry_after_value(headers: &HeaderMap) -> DelayAfter {
166165
DelayAfter::Date(header.to_string())
167166
}
168167

169-
#[async_recursion]
170-
async fn execute_rpc_with_retries<T: DeserializeOwned + std::marker::Send>(
171-
client: &Client,
168+
fn execute_rpc_with_retries<'a, T: DeserializeOwned + std::marker::Send>(
169+
client: &'a Client,
172170
url: Url,
173-
request: &Request,
171+
request: &'a Request,
174172
id: RequestId,
175173
retries: Retries,
176-
) -> Result<T> {
177-
match execute_rpc(client, url.clone(), request, id).await {
178-
Ok(output) => Ok(output),
179-
Err(Error::Transport(error)) => match error {
180-
TransportError::Code(code) => {
181-
if retries.max_retries <= 0
182-
|| retries.sleep_for <= Duration::from_secs(0)
183-
|| (code != 429 && code < 500)
184-
{
185-
return Err(Error::Transport(error));
186-
}
174+
) -> BoxFuture<'a, Result<T>> {
175+
Box::pin(async move {
176+
match execute_rpc(client, url.clone(), request, id).await {
177+
Ok(output) => Ok(output),
178+
Err(Error::Transport(error)) => match error {
179+
TransportError::Code(code) => {
180+
if retries.max_retries <= 0
181+
|| retries.sleep_for <= Duration::from_secs(0)
182+
|| (code != 429 && code < 500)
183+
{
184+
return Err(Error::Transport(error));
185+
}
187186

188-
Delay::new(retries.sleep_for).await;
189-
execute_rpc_with_retries(client, url, request, id, retries.step()).await
190-
}
191-
TransportError::Message(message) => Err(Error::Transport(TransportError::Message(message))),
192-
TransportError::RateLimit(limit) => {
193-
if !retries.use_retry_after_header && retries.max_retries <= 0 {
194-
return Err(Error::Transport(TransportError::Code(429)));
187+
Delay::new(retries.sleep_for).await;
188+
execute_rpc_with_retries(client, url, request, id, retries.step()).await
195189
}
190+
TransportError::Message(message) => Err(Error::Transport(TransportError::Message(message))),
191+
TransportError::RateLimit(limit) => {
192+
if !retries.use_retry_after_header && retries.max_retries <= 0 {
193+
return Err(Error::Transport(TransportError::Code(429)));
194+
}
196195

197-
match limit {
198-
RateLimit::Date(date) => {
199-
let Ok(until) = DateTime::parse_from_rfc2822(&date) else {
200-
return Err(Error::Transport(TransportError::Code(429)));
201-
};
196+
match limit {
197+
RateLimit::Date(date) => {
198+
let Ok(until) = DateTime::parse_from_rfc2822(&date) else {
199+
return Err(Error::Transport(TransportError::Code(429)));
200+
};
202201

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

209-
execute_rpc_with_retries(client, url, request, id, retries.step()).await
210-
}
211-
RateLimit::Seconds(seconds) => {
212-
Delay::new(Duration::from_secs(seconds)).await;
213-
execute_rpc_with_retries(client, url, request, id, retries.step()).await
208+
execute_rpc_with_retries(client, url, request, id, retries.step()).await
209+
}
210+
RateLimit::Seconds(seconds) => {
211+
Delay::new(Duration::from_secs(seconds)).await;
212+
execute_rpc_with_retries(client, url, request, id, retries.step()).await
213+
}
214214
}
215215
}
216-
}
217-
},
218-
Err(err) => Err(err),
219-
}
216+
},
217+
Err(err) => Err(err),
218+
}
219+
})
220220
}
221221

222222
type RpcResult = Result<Value>;

0 commit comments

Comments
 (0)