alloy_consensus/transaction/meta.rs
1//! Commonly used types that contain metadata about a transaction.
2
3use alloy_primitives::{BlockHash, TxHash, B256};
4
5/// Additional fields in the context of a block that contains this _mined_ transaction.
6///
7/// This contains mandatory block fields (block hash, number, timestamp, index).
8#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
9pub struct TransactionMeta {
10 /// Hash of the transaction.
11 pub tx_hash: B256,
12 /// Index of the transaction in the block
13 pub index: u64,
14 /// Hash of the block.
15 pub block_hash: B256,
16 /// Number of the block.
17 pub block_number: u64,
18 /// Base fee of the block.
19 pub base_fee: Option<u64>,
20 /// The excess blob gas of the block.
21 pub excess_blob_gas: Option<u64>,
22 /// The block's timestamp.
23 pub timestamp: u64,
24}
25
26/// Additional fields in the context of a (maybe) pending block that contains this transaction.
27///
28/// This is commonly used when dealing with transactions for rpc where the block context is not
29/// known.
30#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
31#[doc(alias = "TxInfo")]
32pub struct TransactionInfo {
33 /// Hash of the transaction.
34 pub hash: Option<TxHash>,
35 /// Index of the transaction in the block
36 pub index: Option<u64>,
37 /// Hash of the block.
38 pub block_hash: Option<BlockHash>,
39 /// Number of the block.
40 pub block_number: Option<u64>,
41 /// Base fee of the block.
42 pub base_fee: Option<u64>,
43}
44
45impl TransactionInfo {
46 /// Returns a new [`TransactionInfo`] with the provided base fee.
47 pub const fn with_base_fee(mut self, base_fee: u64) -> Self {
48 self.base_fee = Some(base_fee);
49 self
50 }
51}