1use crate::{traits::PropagateKind, PoolTransaction, SubPool, ValidPoolTransaction};
2use alloy_primitives::{TxHash, B256};
3use std::sync::Arc;
45#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
78/// An event that happened to a transaction and contains its full body where possible.
9#[derive(Debug)]
10pub enum FullTransactionEvent<T: PoolTransaction> {
11/// Transaction has been added to the pending pool.
12Pending(TxHash),
13/// Transaction has been added to the queued pool.
14Queued(TxHash),
15/// Transaction has been included in the block belonging to this hash.
16Mined {
17/// The hash of the mined transaction.
18tx_hash: TxHash,
19/// The hash of the mined block that contains the transaction.
20block_hash: B256,
21 },
22/// Transaction has been replaced by the transaction belonging to the hash.
23 ///
24 /// E.g. same (sender + nonce) pair
25Replaced {
26/// The transaction that was replaced.
27transaction: Arc<ValidPoolTransaction<T>>,
28/// The transaction that replaced the event subject.
29replaced_by: TxHash,
30 },
31/// Transaction was dropped due to configured limits.
32Discarded(TxHash),
33/// Transaction became invalid indefinitely.
34Invalid(TxHash),
35/// Transaction was propagated to peers.
36Propagated(Arc<Vec<PropagateKind>>),
37}
3839impl<T: PoolTransaction> Clonefor FullTransactionEvent<T> {
40fn clone(&self) -> Self {
41match self{
42Self::Pending(hash) => Self::Pending(*hash),
43Self::Queued(hash) => Self::Queued(*hash),
44Self::Mined { tx_hash, block_hash } => {
45Self::Mined { tx_hash: *tx_hash, block_hash: *block_hash }
46 }
47Self::Replaced { transaction, replaced_by } => {
48Self::Replaced { transaction: Arc::clone(transaction), replaced_by: *replaced_by }
49 }
50Self::Discarded(hash) => Self::Discarded(*hash),
51Self::Invalid(hash) => Self::Invalid(*hash),
52Self::Propagated(propagated) => Self::Propagated(Arc::clone(propagated)),
53 }
54 }
55}
5657/// Various events that describe status changes of a transaction.
58#[derive(Debug, Clone, Eq, PartialEq)]
59#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
60pub enum TransactionEvent {
61/// Transaction has been added to the pending pool.
62Pending,
63/// Transaction has been added to the queued pool.
64Queued,
65/// Transaction has been included in the block belonging to this hash.
66Mined(B256),
67/// Transaction has been replaced by the transaction belonging to the hash.
68 ///
69 /// E.g. same (sender + nonce) pair
70Replaced(TxHash),
71/// Transaction was dropped due to configured limits.
72Discarded,
73/// Transaction became invalid indefinitely.
74Invalid,
75/// Transaction was propagated to peers.
76Propagated(Arc<Vec<PropagateKind>>),
77}
7879impl TransactionEvent {
80/// Returns `true` if the event is final and no more events are expected for this transaction
81 /// hash.
82pub const fn is_final(&self) -> bool {
83matches!(self, Self::Replaced(_) | Self::Mined(_) | Self::Discarded)
84 }
85}
8687/// Represents a new transaction
88#[derive(Debug)]
89pub struct NewTransactionEvent<T: PoolTransaction> {
90/// The pool which the transaction was moved to.
91pub subpool: SubPool,
92/// Actual transaction
93pub transaction: Arc<ValidPoolTransaction<T>>,
94}
9596impl<T: PoolTransaction> Clonefor NewTransactionEvent<T> {
97fn clone(&self) -> Self {
98Self { subpool: self.subpool, transaction: self.transaction.clone() }
99 }
100}