Skip to content

Commit

Permalink
chore: use safe get api (#1886)
Browse files Browse the repository at this point in the history
* feat: add match_versioned_hashes

* bet

* touchup

---------

Co-authored-by: Khanh Hoa <[email protected]>
  • Loading branch information
mattsse and hoank101 authored Jan 4, 2025
1 parent f7f7ed8 commit 40e3378
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ impl core::fmt::Debug for BlobTransactionSidecar {
}

impl BlobTransactionSidecar {
/// Matches versioned hashes and returns an iterator of (index, BlobAndProofV1) pairs
/// where index is the position in versioned_hashes that matched.
/// Matches versioned hashes and returns an iterator of (index, [`BlobAndProofV1`]) pairs
/// where index is the position in `versioned_hashes` that matched the versioned hash in the
/// sidecar.
///
/// This is used for the `engine_getBlobsV1` RPC endpoint of the engine API
pub fn match_versioned_hashes<'a>(
&'a self,
versioned_hashes: &'a [B256],
) -> impl Iterator<Item = (usize, BlobAndProofV1)> + 'a {
self.versioned_hashes().enumerate().flat_map(move |(i, blob_versioned_hash)| {
versioned_hashes.iter().enumerate().filter_map(move |(j, target_hash)| {
if blob_versioned_hash == *target_hash {
Some((
j,
BlobAndProofV1 { blob: Box::new(self.blobs[i]), proof: self.proofs[i] },
))
} else {
None
if let Some((blob, proof)) =
self.blobs.get(i).copied().zip(self.proofs.get(i).copied())
{
return Some((j, BlobAndProofV1 { blob: Box::new(blob), proof }));
}
}
None
})
})
}
Expand Down

0 comments on commit 40e3378

Please sign in to comment.