Skip to content

Commit a3c4d4c

Browse files
committed
Add convenience methods for universal bundle type
1 parent 1a695ea commit a3c4d4c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

searcher-api-types/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloy_primitives::{BlockNumber, Bytes};
2+
use alloy_rlp::encode;
13
use serde::{Deserialize, Serialize};
24

35
pub mod beaver;
@@ -20,3 +22,45 @@ pub enum SendBundleRequest {
2022
/// Titan Builder bundle
2123
Titan(TitanBundle),
2224
}
25+
26+
impl SendBundleRequest {
27+
pub fn min_timestamp(&self) -> Option<u64> {
28+
match self {
29+
SendBundleRequest::Flashbots(bundle) => bundle.min_timestamp,
30+
SendBundleRequest::Beaver(bundle) => bundle.min_timestamp,
31+
SendBundleRequest::Titan(bundle) => bundle.min_timestamp,
32+
}
33+
}
34+
35+
pub fn max_timestamp(&self) -> Option<u64> {
36+
match self {
37+
SendBundleRequest::Flashbots(bundle) => bundle.max_timestamp,
38+
SendBundleRequest::Beaver(bundle) => bundle.max_timestamp,
39+
SendBundleRequest::Titan(bundle) => bundle.max_timestamp,
40+
}
41+
}
42+
43+
pub fn block_number(&self) -> BlockNumber {
44+
match self {
45+
SendBundleRequest::Flashbots(bundle) => bundle.block_number,
46+
SendBundleRequest::Beaver(bundle) => bundle.block_number,
47+
SendBundleRequest::Titan(bundle) => bundle.block_number,
48+
}
49+
}
50+
51+
pub fn tx_bytes(&self) -> Vec<Bytes> {
52+
match self {
53+
SendBundleRequest::Flashbots(bundle) => bundle.txs.clone(),
54+
SendBundleRequest::Beaver(bundle) => bundle
55+
.transactions
56+
.iter()
57+
.map(|tx| encode(tx).into())
58+
.collect(),
59+
SendBundleRequest::Titan(bundle) => bundle
60+
.transactions
61+
.iter()
62+
.map(|tx| encode(tx).into())
63+
.collect(),
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)