mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-26 15:48:13 -05:00
feat: simplify envelope conversion (#14146)
This commit is contained in:
@@ -544,6 +544,19 @@ impl From<TxEnvelope> for TransactionSigned {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionSigned> for TxEnvelope {
|
||||
fn from(value: TransactionSigned) -> Self {
|
||||
let (tx, signature, hash) = value.into_parts();
|
||||
match tx {
|
||||
Transaction::Legacy(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
Transaction::Eip2930(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
Transaction::Eip1559(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
Transaction::Eip4844(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
Transaction::Eip7702(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionSigned> for Signed<Transaction> {
|
||||
fn from(value: TransactionSigned) -> Self {
|
||||
let (tx, sig, hash) = value.into_parts();
|
||||
|
||||
@@ -171,6 +171,19 @@ impl From<OpTxEnvelope> for OpTransactionSigned {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpTransactionSigned> for OpTxEnvelope {
|
||||
fn from(value: OpTransactionSigned) -> Self {
|
||||
let (tx, signature, hash) = value.into_parts();
|
||||
match tx {
|
||||
OpTypedTransaction::Legacy(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Eip2930(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Eip1559(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Deposit(tx) => Sealed::new_unchecked(tx, hash).into(),
|
||||
OpTypedTransaction::Eip7702(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpTransactionSigned> for Signed<OpTypedTransaction> {
|
||||
fn from(value: OpTransactionSigned) -> Self {
|
||||
let (tx, sig, hash) = value.into_parts();
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
//! Loads and formats OP transaction RPC response.
|
||||
|
||||
use alloy_consensus::{Signed, Transaction as _};
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_primitives::{Bytes, PrimitiveSignature as Signature, Sealable, Sealed, B256};
|
||||
use alloy_rpc_types_eth::TransactionInfo;
|
||||
use op_alloy_consensus::{OpTxEnvelope, OpTypedTransaction};
|
||||
use op_alloy_consensus::OpTxEnvelope;
|
||||
use op_alloy_rpc_types::{OpTransactionRequest, Transaction};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
|
||||
use reth_primitives::Recovered;
|
||||
use reth_primitives_traits::transaction::signed::SignedTransaction;
|
||||
use reth_provider::{
|
||||
BlockReader, BlockReaderIdExt, ProviderTx, ReceiptProvider, TransactionsProvider,
|
||||
};
|
||||
@@ -87,39 +86,32 @@ where
|
||||
tx: Recovered<OpTransactionSigned>,
|
||||
tx_info: TransactionInfo,
|
||||
) -> Result<Self::Transaction, Self::Error> {
|
||||
let from = tx.signer();
|
||||
let hash = *tx.tx_hash();
|
||||
let (transaction, signature) = tx.into_tx().split();
|
||||
let (tx, from) = tx.into_parts();
|
||||
let mut deposit_receipt_version = None;
|
||||
let mut deposit_nonce = None;
|
||||
|
||||
let inner = match transaction {
|
||||
OpTypedTransaction::Legacy(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Eip2930(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Eip1559(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Eip7702(tx) => Signed::new_unchecked(tx, signature, hash).into(),
|
||||
OpTypedTransaction::Deposit(tx) => {
|
||||
self.inner
|
||||
.eth_api
|
||||
.provider()
|
||||
.receipt_by_hash(hash)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.inspect(|receipt| {
|
||||
if let OpReceipt::Deposit(receipt) = receipt {
|
||||
deposit_receipt_version = receipt.deposit_receipt_version;
|
||||
deposit_nonce = receipt.deposit_nonce;
|
||||
}
|
||||
});
|
||||
let inner: OpTxEnvelope = tx.into();
|
||||
|
||||
OpTxEnvelope::Deposit(tx.seal_unchecked(hash))
|
||||
}
|
||||
};
|
||||
if inner.is_deposit() {
|
||||
// for depost tx we need to fetch the receipt
|
||||
self.inner
|
||||
.eth_api
|
||||
.provider()
|
||||
.receipt_by_hash(inner.tx_hash())
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.inspect(|receipt| {
|
||||
if let OpReceipt::Deposit(receipt) = receipt {
|
||||
deposit_receipt_version = receipt.deposit_receipt_version;
|
||||
deposit_nonce = receipt.deposit_nonce;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let TransactionInfo {
|
||||
block_hash, block_number, index: transaction_index, base_fee, ..
|
||||
} = tx_info;
|
||||
|
||||
let effective_gas_price = if matches!(inner, OpTxEnvelope::Deposit(_)) {
|
||||
let effective_gas_price = if inner.is_deposit() {
|
||||
// For deposits, we must always set the `gasPrice` field to 0 in rpc
|
||||
// deposit tx don't have a gas price field, but serde of `Transaction` will take care of
|
||||
// it
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
//! L1 `eth` API types.
|
||||
|
||||
use alloy_consensus::{Signed, Transaction as _, TxEip4844Variant, TxEnvelope};
|
||||
use alloy_consensus::{Transaction as _, TxEip4844Variant, TxEnvelope};
|
||||
use alloy_network::{Ethereum, Network};
|
||||
use alloy_primitives::PrimitiveSignature as Signature;
|
||||
use alloy_rpc_types::TransactionRequest;
|
||||
use alloy_rpc_types_eth::{Transaction, TransactionInfo};
|
||||
use reth_primitives::{Recovered, TransactionSigned};
|
||||
use reth_primitives_traits::SignedTransaction;
|
||||
use reth_rpc_eth_api::EthApiTypes;
|
||||
use reth_rpc_eth_types::EthApiError;
|
||||
use reth_rpc_types_compat::TransactionCompat;
|
||||
@@ -43,27 +42,8 @@ where
|
||||
tx: Recovered<TransactionSigned>,
|
||||
tx_info: TransactionInfo,
|
||||
) -> Result<Self::Transaction, Self::Error> {
|
||||
let from = tx.signer();
|
||||
let hash = *tx.tx_hash();
|
||||
let signature = *tx.signature();
|
||||
|
||||
let inner: TxEnvelope = match tx.into_tx().into_transaction() {
|
||||
reth_primitives::Transaction::Legacy(tx) => {
|
||||
Signed::new_unchecked(tx, signature, hash).into()
|
||||
}
|
||||
reth_primitives::Transaction::Eip2930(tx) => {
|
||||
Signed::new_unchecked(tx, signature, hash).into()
|
||||
}
|
||||
reth_primitives::Transaction::Eip1559(tx) => {
|
||||
Signed::new_unchecked(tx, signature, hash).into()
|
||||
}
|
||||
reth_primitives::Transaction::Eip4844(tx) => {
|
||||
Signed::new_unchecked(tx, signature, hash).into()
|
||||
}
|
||||
reth_primitives::Transaction::Eip7702(tx) => {
|
||||
Signed::new_unchecked(tx, signature, hash).into()
|
||||
}
|
||||
};
|
||||
let (tx, from) = tx.into_parts();
|
||||
let inner: TxEnvelope = tx.into();
|
||||
|
||||
let TransactionInfo {
|
||||
block_hash, block_number, index: transaction_index, base_fee, ..
|
||||
|
||||
Reference in New Issue
Block a user