reth_primitives_traits/
receipt.rs

1//! Receipt abstraction
2
3use crate::{InMemorySize, MaybeCompact, MaybeSerde};
4use alloc::vec::Vec;
5use alloy_consensus::{
6    Eip2718EncodableReceipt, RlpDecodableReceipt, RlpEncodableReceipt, TxReceipt, Typed2718,
7};
8use core::fmt;
9
10/// Helper trait that unifies all behaviour required by receipt to support full node operations.
11pub trait FullReceipt: Receipt + MaybeCompact {}
12
13impl<T> FullReceipt for T where T: Receipt + MaybeCompact {}
14
15/// Abstraction of a receipt.
16#[auto_impl::auto_impl(&, Arc)]
17pub trait Receipt:
18    Send
19    + Sync
20    + Unpin
21    + Clone
22    + fmt::Debug
23    + TxReceipt<Log = alloy_primitives::Log>
24    + RlpEncodableReceipt
25    + RlpDecodableReceipt
26    + Eip2718EncodableReceipt
27    + Typed2718
28    + MaybeSerde
29    + InMemorySize
30{
31}
32
33/// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used).
34pub fn gas_spent_by_transactions<I, T>(receipts: I) -> Vec<(u64, u64)>
35where
36    I: IntoIterator<Item = T>,
37    T: TxReceipt,
38{
39    receipts
40        .into_iter()
41        .enumerate()
42        .map(|(id, receipt)| (id as u64, receipt.cumulative_gas_used() as u64))
43        .collect()
44}