Skip to content

Commit b936782

Browse files
committed
feat: add back reqwest and hyper features
1 parent 6ba35d2 commit b936782

5 files changed

Lines changed: 35 additions & 10 deletions

File tree

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description = """
1212
Easily send transaction bundles using Alloy.
1313
"""
1414

15+
1516
[dependencies]
1617
alloy = { version = "1.0.30", features = [
1718
"rpc",
@@ -24,7 +25,8 @@ alloy = { version = "1.0.30", features = [
2425
"transports",
2526
"transport-http",
2627
"signers",
27-
] }
28+
], default-features = false }
29+
cfg-if = "1.0.3"
2830
futures = "0.3"
2931
pin-project = "1.1"
3032
url = "2.5"
@@ -41,6 +43,11 @@ alloy = { version = "1.0.30", features = [
4143
"signer-local",
4244
] }
4345

46+
[features]
47+
default = ["reqwest"]
48+
reqwest = ["alloy/reqwest"]
49+
hyper = ["alloy/hyper"]
50+
4451
[package.metadata.docs.rs]
4552
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
4653

src/eth/broadcastable_call.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ use std::{fmt::Debug, future::IntoFuture, marker::PhantomData, pin::Pin};
33
use alloy::{
44
providers::ext::MevBuilder,
55
rpc::{
6-
client::{RpcCall, RpcClient},
6+
client::RpcCall,
77
json_rpc::{Request, RpcObject},
88
},
99
transports::{BoxFuture, TransportResult},
1010
};
1111
use futures::{future::join_all, Future, FutureExt};
1212
use pin_project::pin_project;
1313

14+
use crate::utils::build_rpc_client;
15+
1416
use super::Endpoints;
1517

1618
/// Allows to broadcast a request to many RPC endpoints.
@@ -31,7 +33,7 @@ where
3133
let calls = endpoints
3234
.iter()
3335
.map(|e| {
34-
let client = RpcClient::new_http(e.url.clone());
36+
let client = build_rpc_client(e.url.clone());
3537
let rpc_call = RpcCall::new(request.clone(), client.transport().clone());
3638
let mut mev = MevBuilder::new_rpc(rpc_call);
3739
if let Some(signer) = &e.signer {

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ pub use eth::{
1616

1717
mod mev_share;
1818
pub use mev_share::{MevShareBundleBuilder, MevShareProviderExt};
19+
20+
mod utils;

src/mev_share/provider_ext.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use alloy::{
22
network::Network,
33
providers::{ext::MevBuilder, Provider},
4-
rpc::{
5-
client::RpcClient,
6-
types::mev::{EthBundleHash, MevSendBundle, SimBundleOverrides, SimBundleResponse},
7-
},
4+
rpc::types::mev::{EthBundleHash, MevSendBundle, SimBundleOverrides, SimBundleResponse},
85
signers::Signer,
96
transports::TransportResult,
107
};
118
use async_trait::async_trait;
129

13-
use crate::mev_share::{MevShareBundleBuilder, FLASHBOTS_RELAY_RPC_URL};
10+
use crate::{
11+
mev_share::{MevShareBundleBuilder, FLASHBOTS_RELAY_RPC_URL},
12+
utils::build_rpc_client,
13+
};
1414

1515
/// Extension trait for sending and simulate MEV-Share bundles.
1616
#[async_trait]
@@ -62,7 +62,7 @@ where
6262
where
6363
S: Signer + Clone + Send + Sync + 'static,
6464
{
65-
let client = RpcClient::new_http(FLASHBOTS_RELAY_RPC_URL.parse().unwrap());
65+
let client = build_rpc_client(FLASHBOTS_RELAY_RPC_URL.parse().unwrap());
6666
let request = client.request("mev_sendBundle", (bundle,));
6767

6868
MevBuilder::new_rpc(request).with_auth(signer).await
@@ -77,7 +77,7 @@ where
7777
where
7878
S: Signer + Clone + Send + Sync + 'static,
7979
{
80-
let client = RpcClient::new_http(FLASHBOTS_RELAY_RPC_URL.parse().unwrap());
80+
let client = build_rpc_client(FLASHBOTS_RELAY_RPC_URL.parse().unwrap());
8181
let request = client.request("mev_simBundle", (bundle, sim_overrides));
8282

8383
MevBuilder::new_rpc(request).with_auth(signer).await

src/utils.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use alloy::rpc::client::RpcClient;
2+
use url::Url;
3+
4+
pub(crate) fn build_rpc_client(url: Url) -> RpcClient {
5+
cfg_if::cfg_if! {
6+
if #[cfg(feature = "reqwest")] {
7+
RpcClient::new_http(url)
8+
} else if #[cfg(feature = "hyper")] {
9+
RpcClient::builder().new_hyper(url)
10+
} else {
11+
panic!("One of 'reqwest' or 'hyper' features must be enabled")
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)