reth_primitives_traits/
receipt.rs

1//! Receipt abstraction
2
3use crate::{InMemorySize, MaybeCompact, MaybeSerde, MaybeSerdeBincodeCompat};
4use alloc::vec::Vec;
5use alloy_consensus::{
6    Eip2718EncodableReceipt, RlpDecodableReceipt, RlpEncodableReceipt, TxReceipt, Typed2718,
7};
8use alloy_rlp::{Decodable, Encodable};
9use core::fmt;
10
11/// Helper trait that unifies all behaviour required by receipt to support full node operations.
12pub trait FullReceipt: Receipt + MaybeCompact {}
13
14impl<T> FullReceipt for T where T: Receipt + MaybeCompact {}
15
16/// Abstraction of a receipt.
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    + Encodable
27    + Decodable
28    + Eip2718EncodableReceipt
29    + Typed2718
30    + MaybeSerde
31    + InMemorySize
32    + MaybeSerdeBincodeCompat
33{
34}
35
36// Blanket implementation for any type that satisfies all the supertrait bounds
37impl<T> Receipt for T where
38    T: Send
39        + Sync
40        + Unpin
41        + Clone
42        + fmt::Debug
43        + TxReceipt<Log = alloy_primitives::Log>
44        + RlpEncodableReceipt
45        + RlpDecodableReceipt
46        + Encodable
47        + Decodable
48        + Eip2718EncodableReceipt
49        + Typed2718
50        + MaybeSerde
51        + InMemorySize
52        + MaybeSerdeBincodeCompat
53{
54}
55
56/// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used).
57pub fn gas_spent_by_transactions<I, T>(receipts: I) -> Vec<(u64, u64)>
58where
59    I: IntoIterator<Item = T>,
60    T: TxReceipt,
61{
62    receipts
63        .into_iter()
64        .enumerate()
65        .map(|(id, receipt)| (id as u64, receipt.cumulative_gas_used()))
66        .collect()
67}