arb_txpool/
transaction.rs

1use alloy_consensus::{
2    transaction::{Recovered, TxHashRef},
3    BlobTransactionValidationError, Typed2718,
4};
5use alloy_eips::{
6    eip2718::WithEncoded, eip2930::AccessList, eip7594::BlobTransactionSidecarVariant,
7    Encodable2718,
8};
9use alloy_primitives::{Address, Bytes, TxHash, TxKind, B256, U256};
10use c_kzg::KzgSettings;
11use core::convert::Infallible;
12use derive_more::Deref;
13use reth_primitives_traits::InMemorySize;
14use reth_transaction_pool::{
15    EthBlobTransactionSidecar, EthPoolTransaction, EthPooledTransaction, PoolTransaction,
16};
17
18use arb_primitives::ArbTransactionSigned;
19
20/// Pooled Arbitrum transaction wrapping the standard pool transaction type.
21#[derive(Debug, Clone, Deref)]
22pub struct ArbPooledTransaction {
23    inner: EthPooledTransaction<ArbTransactionSigned>,
24}
25
26impl ArbPooledTransaction {
27    /// Create a new pooled transaction.
28    pub fn new(transaction: Recovered<ArbTransactionSigned>, encoded_length: usize) -> Self {
29        Self {
30            inner: EthPooledTransaction::new(transaction, encoded_length),
31        }
32    }
33}
34
35impl PoolTransaction for ArbPooledTransaction {
36    type TryFromConsensusError = Infallible;
37    type Consensus = ArbTransactionSigned;
38    type Pooled = ArbTransactionSigned;
39
40    fn consensus_ref(&self) -> Recovered<&Self::Consensus> {
41        Recovered::new_unchecked(&*self.inner.transaction, self.inner.transaction.signer())
42    }
43
44    fn clone_into_consensus(&self) -> Recovered<Self::Consensus> {
45        self.inner.transaction().clone()
46    }
47
48    fn into_consensus(self) -> Recovered<Self::Consensus> {
49        self.inner.transaction
50    }
51
52    fn into_consensus_with2718(self) -> WithEncoded<Recovered<Self::Consensus>> {
53        let encoding: Bytes = self.inner.transaction().encoded_2718().into();
54        self.inner.transaction.into_encoded_with(encoding)
55    }
56
57    fn from_pooled(tx: Recovered<Self::Pooled>) -> Self {
58        let encoded_len = tx.encode_2718_len();
59        Self::new(tx, encoded_len)
60    }
61
62    fn hash(&self) -> &TxHash {
63        self.inner.transaction.tx_hash()
64    }
65
66    fn sender(&self) -> Address {
67        self.inner.transaction.signer()
68    }
69
70    fn sender_ref(&self) -> &Address {
71        self.inner.transaction.signer_ref()
72    }
73
74    fn cost(&self) -> &U256 {
75        &self.inner.cost
76    }
77
78    fn encoded_length(&self) -> usize {
79        self.inner.encoded_length
80    }
81}
82
83impl InMemorySize for ArbPooledTransaction {
84    fn size(&self) -> usize {
85        self.inner.size()
86    }
87}
88
89impl alloy_consensus::Transaction for ArbPooledTransaction {
90    fn chain_id(&self) -> Option<u64> {
91        self.inner.chain_id()
92    }
93    fn nonce(&self) -> u64 {
94        self.inner.nonce()
95    }
96    fn gas_limit(&self) -> u64 {
97        self.inner.gas_limit()
98    }
99    fn gas_price(&self) -> Option<u128> {
100        self.inner.gas_price()
101    }
102    fn max_fee_per_gas(&self) -> u128 {
103        self.inner.max_fee_per_gas()
104    }
105    fn max_priority_fee_per_gas(&self) -> Option<u128> {
106        self.inner.max_priority_fee_per_gas()
107    }
108    fn max_fee_per_blob_gas(&self) -> Option<u128> {
109        self.inner.max_fee_per_blob_gas()
110    }
111    fn priority_fee_or_price(&self) -> u128 {
112        self.inner.priority_fee_or_price()
113    }
114    fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
115        self.inner.effective_gas_price(base_fee)
116    }
117    fn is_dynamic_fee(&self) -> bool {
118        self.inner.is_dynamic_fee()
119    }
120    fn kind(&self) -> TxKind {
121        self.inner.kind()
122    }
123    fn is_create(&self) -> bool {
124        self.inner.is_create()
125    }
126    fn value(&self) -> U256 {
127        self.inner.value()
128    }
129    fn input(&self) -> &Bytes {
130        self.inner.input()
131    }
132    fn access_list(&self) -> Option<&AccessList> {
133        self.inner.access_list()
134    }
135    fn blob_versioned_hashes(&self) -> Option<&[B256]> {
136        self.inner.blob_versioned_hashes()
137    }
138    fn authorization_list(&self) -> Option<&[alloy_eips::eip7702::SignedAuthorization]> {
139        None
140    }
141}
142
143impl Typed2718 for ArbPooledTransaction {
144    fn ty(&self) -> u8 {
145        self.inner.ty()
146    }
147}
148
149impl EthPoolTransaction for ArbPooledTransaction {
150    fn take_blob(&mut self) -> EthBlobTransactionSidecar {
151        EthBlobTransactionSidecar::None
152    }
153
154    fn try_into_pooled_eip4844(
155        self,
156        _sidecar: std::sync::Arc<BlobTransactionSidecarVariant>,
157    ) -> Option<Recovered<Self::Pooled>> {
158        None
159    }
160
161    fn try_from_eip4844(
162        _tx: Recovered<Self::Consensus>,
163        _sidecar: BlobTransactionSidecarVariant,
164    ) -> Option<Self> {
165        None
166    }
167
168    fn validate_blob(
169        &self,
170        _blob: &BlobTransactionSidecarVariant,
171        _settings: &KzgSettings,
172    ) -> Result<(), BlobTransactionValidationError> {
173        Err(BlobTransactionValidationError::NotBlobTransaction(
174            self.ty(),
175        ))
176    }
177}