From d2691e320bb56c37f663ff94e6b149594e13a535 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 7 Sep 2024 11:43:19 +0200 Subject: [PATCH] chore: add helpers for beacon blob bundle --- crates/rpc-types-beacon/src/sidecar.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types-beacon/src/sidecar.rs b/crates/rpc-types-beacon/src/sidecar.rs index 7ec97f9ecb30..a21b45fcd663 100644 --- a/crates/rpc-types-beacon/src/sidecar.rs +++ b/crates/rpc-types-beacon/src/sidecar.rs @@ -10,7 +10,29 @@ use std::vec::IntoIter; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct BeaconBlobBundle { /// Vec of individual blob data - data: Vec, + pub data: Vec, +} + +impl BeaconBlobBundle { + /// Creates a new [`BeaconBlobBundle`] from a given vector of [`BlobData`]. + pub fn new(data: Vec) -> Self { + Self { data } + } + + /// Returns the number of blobs in the bundle. + pub fn len(&self) -> usize { + self.data.len() + } + + /// Returns if the bundle is empty. + pub fn is_empty(&self) -> bool { + self.data.is_empty() + } + + /// Returns the blob with the given index. + pub fn get_blob(&self, index: u64) -> Option<&BlobData> { + self.data.iter().find(|blob| blob.index == index) + } } /// Yields an iterator for BlobData