Skip to content

Commit 2a7ee26

Browse files
committed
lint: clippy
1 parent f5a60aa commit 2a7ee26

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["init4", "bin", "base"]
66

77
version = "0.12.4"
88
edition = "2021"
9-
rust-version = "1.81"
9+
rust-version = "1.83"
1010
authors = ["init4", "James Prestwich", "evalir"]
1111
license = "MIT OR Apache-2.0"
1212
homepage = "https://github.com/init4tech/bin-base"

src/utils/flashbots.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,41 @@ impl FlashbotsConfig {
3535
}
3636
}
3737

38-
/// A wrapper over a `Provider` that adds Flashbots MEV bundle helpers.
38+
/// A basic provider for common Flashbots Relay endpoints.
3939
#[derive(Debug)]
4040
pub struct Flashbots {
4141
/// The base URL for the Flashbots API.
4242
pub relay_url: url::Url,
4343

4444
/// Signer is loaded once at startup.
4545
signer: LocalOrAws,
46+
47+
/// The reqwest client to use for requests.
48+
client: reqwest::Client,
4649
}
4750

4851
impl Flashbots {
49-
/// Wraps a provider with the URL and returns a new `FlashbotsProvider`.
50-
pub const fn new(relay_url: url::Url, signer: LocalOrAws) -> Self {
51-
Self { relay_url, signer }
52+
/// Instantiate a new provider from the URL and signer.
53+
pub fn new(relay_url: url::Url, signer: LocalOrAws) -> Self {
54+
Self {
55+
relay_url,
56+
client: Default::default(),
57+
signer,
58+
}
59+
}
60+
61+
/// Instantiate a new provider from the URL and signer, with a specific
62+
/// Reqwest client.
63+
pub const fn new_with_client(
64+
relay_url: url::Url,
65+
signer: LocalOrAws,
66+
client: reqwest::Client,
67+
) -> Self {
68+
Self {
69+
relay_url,
70+
client,
71+
signer,
72+
}
5273
}
5374

5475
/// Sends a bundle via `mev_sendBundle`.
@@ -63,7 +84,7 @@ impl Flashbots {
6384
Ok(())
6485
}
6586

66-
/// Fetches the bundle status by hash
87+
/// Fetch the bundle status by hash.
6788
pub async fn bundle_status(
6889
&self,
6990
hash: EthBundleHash,
@@ -77,7 +98,8 @@ impl Flashbots {
7798
Ok(())
7899
}
79100

80-
/// Makes a raw JSON-RPC call with the Flashbots signature header to the method with the given params.
101+
/// Make a raw JSON-RPC call with the Flashbots signature header to the
102+
/// method with the given params.
81103
async fn raw_call<Params: RpcSend, Payload: RpcRecv>(
82104
&self,
83105
method: &str,
@@ -93,8 +115,8 @@ impl Flashbots {
93115

94116
let value = self.compute_signature(&body_bz).await?;
95117

96-
let client = reqwest::Client::new();
97-
let resp = client
118+
let resp = self
119+
.client
98120
.post(self.relay_url.as_str())
99121
.header(CONTENT_TYPE, "application/json")
100122
.header("X-Flashbots-Signature", value)
@@ -112,7 +134,8 @@ impl Flashbots {
112134
}
113135
}
114136

115-
/// Builds an EIP-191 signature for the given body bytes.
137+
/// Builds an EIP-191 signature for the given body bytes. This signature is
138+
/// used to authenticate to the relay API via a header
116139
async fn compute_signature(&self, body_bz: &[u8]) -> Result<String, eyre::Error> {
117140
let payload = keccak256(body_bz).to_string();
118141
let signature = self.signer.sign_message(payload.as_ref()).await?;

tests/flashbots.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn get_test_provider() -> Flashbots {
3333
Flashbots::new(FLASHBOTS_URL.clone(), BUILDER_KEY.clone())
3434
}
3535

36+
#[allow(clippy::type_complexity)]
3637
fn get_sepolia() -> FillProvider<
3738
JoinFill<
3839
JoinFill<

0 commit comments

Comments
 (0)