Skip to content

Commit

Permalink
chore: add helpers for beacon blob bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Sep 7, 2024
1 parent 122c4b1 commit d2691e3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion crates/rpc-types-beacon/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlobData>,
pub data: Vec<BlobData>,
}

impl BeaconBlobBundle {
/// Creates a new [`BeaconBlobBundle`] from a given vector of [`BlobData`].
pub fn new(data: Vec<BlobData>) -> 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
Expand Down

0 comments on commit d2691e3

Please sign in to comment.