Skip to content

Commit 1a695ea

Browse files
committed
Add helper for bundle construction
1 parent e30e7e5 commit 1a695ea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

searcher-api-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ serde_json = { workspace = true }
99

1010
serde_with = "3.0.0"
1111
alloy-primitives = "0.8"
12+
alloy-rlp = "0.3"
1213
alloy-rpc-types-mev = "0.8"
1314
alloy-serde = "0.8"
1415
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "1e965caf5fa176f244a31c0d2662ba1b590938db" } # Reth 1.2
16+
eyre = "0.6.12"

searcher-api-types/src/beaver.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! RPC types that are supported by Beaverbuild
2-
use alloy_primitives::{Address, BlockNumber, TxHash};
2+
use alloy_primitives::{hex, Address, BlockNumber, TxHash};
3+
use alloy_rlp::Decodable;
4+
use eyre::eyre;
35
use reth_primitives::TransactionSigned;
46
use serde::{Deserialize, Serialize};
57
use serde_with::{serde_as, skip_serializing_none};
@@ -40,6 +42,26 @@ pub struct BeaverBundle {
4042
pub refund_transaction_hashes: Vec<TxHash>,
4143
}
4244

45+
impl BeaverBundle {
46+
pub fn from_rlp_hex(txs: Vec<String>, block_number: BlockNumber) -> eyre::Result<Self> {
47+
Ok(Self {
48+
transactions: txs
49+
.iter()
50+
.map(|hex_string| {
51+
hex::decode(hex_string)
52+
.map_err(|e| eyre!("Invalid hexadecimal string: {e:?}"))
53+
.and_then(|decoded_bytes| {
54+
TransactionSigned::decode(&mut decoded_bytes.as_slice())
55+
.map_err(|e| eyre!("Illegal RLP bytes for transaction: {e:?}"))
56+
})
57+
})
58+
.collect::<Result<Vec<TransactionSigned>, _>>()?,
59+
block_number,
60+
..Self::default()
61+
})
62+
}
63+
}
64+
4365
#[cfg(test)]
4466
mod test {
4567
use super::*;

0 commit comments

Comments
 (0)