reth_transaction_pool/pool/
events.rs1use crate::{traits::PropagateKind, PoolTransaction, SubPool, ValidPoolTransaction};
2use alloy_primitives::{TxHash, B256};
3use std::sync::Arc;
4
5use crate::pool::QueuedReason;
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug)]
11pub enum FullTransactionEvent<T: PoolTransaction> {
12 Pending(TxHash),
14 Queued(TxHash, Option<QueuedReason>),
18 Mined {
20 tx_hash: TxHash,
22 block_hash: B256,
24 },
25 Replaced {
29 transaction: Arc<ValidPoolTransaction<T>>,
31 replaced_by: TxHash,
33 },
34 Discarded(TxHash),
36 Invalid(TxHash),
38 Propagated(Arc<Vec<PropagateKind>>),
40}
41
42impl<T: PoolTransaction> Clone for FullTransactionEvent<T> {
43 fn clone(&self) -> Self {
44 match self {
45 Self::Pending(hash) => Self::Pending(*hash),
46 Self::Queued(hash, reason) => Self::Queued(*hash, reason.clone()),
47 Self::Mined { tx_hash, block_hash } => {
48 Self::Mined { tx_hash: *tx_hash, block_hash: *block_hash }
49 }
50 Self::Replaced { transaction, replaced_by } => {
51 Self::Replaced { transaction: Arc::clone(transaction), replaced_by: *replaced_by }
52 }
53 Self::Discarded(hash) => Self::Discarded(*hash),
54 Self::Invalid(hash) => Self::Invalid(*hash),
55 Self::Propagated(propagated) => Self::Propagated(Arc::clone(propagated)),
56 }
57 }
58}
59
60#[derive(Debug, Clone, Eq, PartialEq)]
62#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
63pub enum TransactionEvent {
64 Pending,
66 Queued,
68 Mined(B256),
70 Replaced(TxHash),
74 Discarded,
76 Invalid,
78 Propagated(Arc<Vec<PropagateKind>>),
80}
81
82impl TransactionEvent {
83 pub const fn is_final(&self) -> bool {
86 matches!(self, Self::Replaced(_) | Self::Mined(_) | Self::Discarded | Self::Invalid)
87 }
88}
89
90#[derive(Debug)]
92pub struct NewTransactionEvent<T: PoolTransaction> {
93 pub subpool: SubPool,
95 pub transaction: Arc<ValidPoolTransaction<T>>,
97}
98
99impl<T: PoolTransaction> NewTransactionEvent<T> {
100 pub const fn pending(transaction: Arc<ValidPoolTransaction<T>>) -> Self {
102 Self { subpool: SubPool::Pending, transaction }
103 }
104}
105
106impl<T: PoolTransaction> Clone for NewTransactionEvent<T> {
107 fn clone(&self) -> Self {
108 Self { subpool: self.subpool, transaction: self.transaction.clone() }
109 }
110}