|
| 1 | +use alloy_consensus::transaction::Recovered; |
1 | 2 | use alloy_consensus::{Transaction, transaction::SignerRecoverable}; |
2 | 3 | use alloy_primitives::{B256, Bytes}; |
3 | 4 | use alloy_provider::{Provider, RootProvider, network::eip2718::Decodable2718}; |
|
88 | 89 | // Decode and validate all transactions |
89 | 90 | let mut total_gas = 0u64; |
90 | 91 | for tx_data in &bundle.txs { |
91 | | - if tx_data.is_empty() { |
92 | | - return Err(EthApiError::EmptyRawTransactionData.into_rpc_err()); |
93 | | - } |
94 | | - |
95 | | - let envelope = OpTxEnvelope::decode_2718_exact(tx_data.iter().as_slice()) |
96 | | - .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
97 | | - |
98 | | - let transaction = envelope |
99 | | - .clone() |
100 | | - .try_into_recovered() |
101 | | - .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
102 | | - |
103 | | - let mut l1_block_info = self.provider.fetch_l1_block_info().await?; |
104 | | - let account = self |
105 | | - .provider |
106 | | - .fetch_account_info(transaction.signer()) |
107 | | - .await?; |
108 | | - validate_tx(account, &transaction, tx_data, &mut l1_block_info).await?; |
| 92 | + let transaction = self.validate_tx(tx_data).await?; |
109 | 93 | total_gas = total_gas.saturating_add(transaction.gas_limit()); |
110 | 94 | } |
111 | 95 |
|
@@ -145,24 +129,7 @@ where |
145 | 129 | } |
146 | 130 |
|
147 | 131 | async fn send_raw_transaction(&self, data: Bytes) -> RpcResult<B256> { |
148 | | - if data.is_empty() { |
149 | | - return Err(EthApiError::EmptyRawTransactionData.into_rpc_err()); |
150 | | - } |
151 | | - |
152 | | - let envelope = OpTxEnvelope::decode_2718_exact(data.iter().as_slice()) |
153 | | - .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
154 | | - |
155 | | - let transaction = envelope |
156 | | - .clone() |
157 | | - .try_into_recovered() |
158 | | - .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
159 | | - |
160 | | - let mut l1_block_info = self.provider.fetch_l1_block_info().await?; |
161 | | - let account = self |
162 | | - .provider |
163 | | - .fetch_account_info(transaction.signer()) |
164 | | - .await?; |
165 | | - validate_tx(account, &transaction, &data, &mut l1_block_info).await?; |
| 132 | + let transaction = self.validate_tx(&data).await?; |
166 | 133 |
|
167 | 134 | let expiry_timestamp = SystemTime::now() |
168 | 135 | .duration_since(UNIX_EPOCH) |
@@ -209,3 +176,31 @@ where |
209 | 176 | Ok(transaction.tx_hash()) |
210 | 177 | } |
211 | 178 | } |
| 179 | + |
| 180 | +impl<Queue> IngressService<Queue> |
| 181 | +where |
| 182 | + Queue: QueuePublisher + Sync + Send + 'static, |
| 183 | +{ |
| 184 | + async fn validate_tx(&self, data: &Bytes) -> RpcResult<Recovered<OpTxEnvelope>> { |
| 185 | + if data.is_empty() { |
| 186 | + return Err(EthApiError::EmptyRawTransactionData.into_rpc_err()); |
| 187 | + } |
| 188 | + |
| 189 | + let envelope = OpTxEnvelope::decode_2718_exact(data.iter().as_slice()) |
| 190 | + .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
| 191 | + |
| 192 | + let transaction = envelope |
| 193 | + .clone() |
| 194 | + .try_into_recovered() |
| 195 | + .map_err(|_| EthApiError::FailedToDecodeSignedTransaction.into_rpc_err())?; |
| 196 | + |
| 197 | + let mut l1_block_info = self.provider.fetch_l1_block_info().await?; |
| 198 | + let account = self |
| 199 | + .provider |
| 200 | + .fetch_account_info(transaction.signer()) |
| 201 | + .await?; |
| 202 | + validate_tx(account, &transaction, data, &mut l1_block_info).await?; |
| 203 | + |
| 204 | + Ok(transaction) |
| 205 | + } |
| 206 | +} |
0 commit comments