chore: move gas_spent_by_transactions to traits (#12541)

This commit is contained in:
Matthias Seitz
2024-11-14 21:35:04 +01:00
committed by GitHub
parent 870ffae909
commit 28a5b631d1
2 changed files with 19 additions and 14 deletions

View File

@ -1,9 +1,9 @@
//! Receipt abstraction
use core::fmt;
use alloc::vec::Vec;
use alloy_consensus::TxReceipt;
use alloy_primitives::B256;
use core::fmt;
use reth_codecs::Compact;
use serde::{Deserialize, Serialize};
@ -32,3 +32,16 @@ pub trait Receipt:
/// Calculates the receipts root of the given receipts.
fn receipts_root(receipts: &[&Self]) -> B256;
}
/// Retrieves gas spent by transactions as a vector of tuples (transaction index, gas used).
pub fn gas_spent_by_transactions<I, T>(receipts: I) -> Vec<(u64, u64)>
where
I: IntoIterator<Item = T>,
T: TxReceipt,
{
receipts
.into_iter()
.enumerate()
.map(|(id, receipt)| (id as u64, receipt.cumulative_gas_used() as u64))
.collect()
}