Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add helpers for beacon blob bundle #1254

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 const 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