diff --git a/crates/rpc-types-debug/Cargo.toml b/crates/rpc-types-debug/Cargo.toml index 6f952849138..c14d6d1e90d 100644 --- a/crates/rpc-types-debug/Cargo.toml +++ b/crates/rpc-types-debug/Cargo.toml @@ -24,6 +24,7 @@ workspace = true [dependencies] alloy-primitives = { workspace = true, features = ["serde"] } +alloy-rlp.workspace = true serde.workspace = true serde_with = { workspace = true, features = ["alloc", "base64"] } diff --git a/crates/rpc-types-debug/src/execution_witness.rs b/crates/rpc-types-debug/src/execution_witness.rs index 1b8b3cc22cd..3de4378496e 100644 --- a/crates/rpc-types-debug/src/execution_witness.rs +++ b/crates/rpc-types-debug/src/execution_witness.rs @@ -1,5 +1,6 @@ use alloc::vec::Vec; use alloy_primitives::Bytes; +use alloy_rlp::Encodable; use serde::{Deserialize, Serialize}; /// Represents the execution witness of a block. Contains lists of required preimages and @@ -62,3 +63,24 @@ pub struct ExecutionWitness { /// 256 block headers. However note, we may not need all 256, like in the example above. pub headers: Vec, } + +impl ExecutionWitness { + /// Sets the `headers` field from already RLP-encoded headers. + pub fn with_rlp_headers(mut self, headers: Vec) -> Self { + self.headers = headers; + self + } + + /// Sets the `headers` field by RLP-encoding each item. + pub fn with_headers(mut self, headers: impl IntoIterator) -> Self { + self.headers = headers + .into_iter() + .map(|header| { + let mut buf = Vec::new(); + header.encode(&mut buf); + buf.into() + }) + .collect(); + self + } +}