Skip to content

Commit fbc2f38

Browse files
committed
Send bundles
1 parent 6a2f46e commit fbc2f38

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ reqwest = { version = "0.12.5", features = ["json"] }
2929
serde = { version = "1.0", features = ["derive"] }
3030
serde_json = { version = "1", features = ["raw_value"] }
3131
superstruct = "0.8"
32-
tokio = { version = "1", default-features = false, features = ["signal", "rt-multi-thread"] }
32+
tokio = { version = "1", default-features = false, features = ["signal", "rt-multi-thread", "macros"] }
3333
tokio-tungstenite = "0.24.0"
3434
tracing = { version = "0.1", features = ["attributes"] }
3535
types = { git = "https://github.com/sigp/lighthouse.git", rev = "c33307d70287fd3b7a70785f89dadcb737214903" }

searcher-client/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
serde = { workspace = true }
8-
serde_json = { workspace = true }
7+
tokio = { workspace = true }
98

10-
alloy-primitives = "0.8"
119
alloy-rpc-types-mev = "0.8"
1210
eyre = "0.6.12"
1311
url = "2.5.4"
14-
reqwest = { version = "0.12", features = ["json"] }
12+
jsonrpsee = { version = "0.24.8", features = ["jsonrpsee-http-client", "jsonrpsee-core"] }
1513

1614
searcher-api-types = { path = "../searcher-api-types" }
15+
jsonrpsee-core = "0.24.8"
16+

searcher-client/src/lib.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
use alloy_rpc_types_mev::EthBundleHash;
2-
use reqwest::Client;
2+
use jsonrpsee::http_client::HttpClient;
3+
use jsonrpsee::rpc_params;
4+
use jsonrpsee_core::client::ClientT;
35
use url::Url;
46

57
use searcher_api_types::SendBundleRequest;
68

79
pub async fn send_bundle(url: Url, bundle: &SendBundleRequest) -> eyre::Result<EthBundleHash> {
8-
Ok(serde_json::from_str(
9-
&Client::new()
10-
.post(url)
11-
.json(bundle)
12-
.send()
13-
.await?
14-
.text()
15-
.await?,
16-
)?)
10+
Ok(HttpClient::builder()
11+
.build(url)?
12+
.request("eth_sendBundle", rpc_params![bundle])
13+
.await?)
14+
}
15+
16+
#[cfg(test)]
17+
mod test {
18+
use super::*;
19+
20+
use searcher_api_types::{BeaverBundle, SendBundleRequest};
21+
22+
const TEST_ENDPOINT: &str = "https://rpc.beaverbuild.org";
23+
24+
fn test_endpoint() -> Url {
25+
TEST_ENDPOINT.parse().unwrap()
26+
}
27+
28+
#[tokio::test]
29+
async fn test_send_bundle_beaver_rejects_empty_bundle() {
30+
let empty_bundle = SendBundleRequest::Beaver(BeaverBundle {
31+
transactions: vec![],
32+
block_number: 0,
33+
..BeaverBundle::default()
34+
});
35+
let res = send_bundle(test_endpoint(), &empty_bundle).await;
36+
assert!(res.is_err());
37+
}
38+
39+
#[tokio::test]
40+
async fn test_send_bundle_beaver_success() {
41+
let bundle = SendBundleRequest::Beaver(BeaverBundle::from_rlp_hex(vec!["0x02f8b20181948449bdee618501dcd6500083016b93942dabcea55a12d73191aece59f508b191fb68adac80b844095ea7b300000000000000000000000054e44dbb92dba848ace27f44c0cb4268981ef1cc00000000000000000000000000000000000000000000000052616e065f6915ebc080a0c497b6e53d7cb78e68c37f6186c8bb9e1b8a55c3e22462163495979b25c2caafa052769811779f438b73159c4cc6a05a889da8c1a16e432c2e37e3415c9a0b9887".to_string()], 1).expect("illegal RLP bytes for bundle"));
42+
let res = send_bundle(test_endpoint(), &bundle).await;
43+
assert!(res.is_ok());
44+
let resp = res.unwrap();
45+
assert_eq!(
46+
resp.bundle_hash.to_string(),
47+
"0xbfe05fa7cb2f9de981eeefe7246c9c9be6f69c3a3b33a05fdbf6afac42ddd294"
48+
);
49+
}
1750
}

0 commit comments

Comments
 (0)