Skip to content

Commit

Permalink
consensus: implement root_slow for Receipts (#1563)
Browse files Browse the repository at this point in the history
* consensus: implement root_slow for Receipts

* clippy
  • Loading branch information
tcoratger authored Oct 25, 2024
1 parent 1a61867 commit b6baa1d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::receipt::{Eip658Value, TxReceipt};
use alloc::{vec, vec::Vec};
use alloy_primitives::{Bloom, Log};
use alloy_primitives::{Bloom, Log, B256};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
use core::{borrow::Borrow, fmt};
use derive_more::{DerefMut, From, IntoIterator};
Expand Down Expand Up @@ -126,6 +126,12 @@ impl<T> Receipts<T> {
pub fn push(&mut self, receipts: Vec<T>) {
self.receipt_vec.push(receipts);
}

/// Retrieves all recorded receipts from index and calculates the root using the given closure.
pub fn root_slow(&self, index: usize, f: impl FnOnce(&[&T]) -> B256) -> Option<B256> {
let receipts = self.receipt_vec.get(index)?.iter().collect::<Vec<_>>();
Some(f(receipts.as_slice()))
}
}

impl<T> From<Vec<T>> for Receipts<T> {
Expand Down

0 comments on commit b6baa1d

Please sign in to comment.