From 7272b217abc22f889ed88bbc3bcff8a8e13ce4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Hodul=C3=A1k?= Date: Fri, 13 Jun 2025 14:49:10 +0200 Subject: [PATCH] feat(rpc): Implement `IntoRpcTx` with Ethereum RPC transaction response for `Extended` (#16783) --- .../rpc/rpc-types-compat/src/transaction.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc-types-compat/src/transaction.rs b/crates/rpc/rpc-types-compat/src/transaction.rs index 4dca40ce27..06f50aebf8 100644 --- a/crates/rpc/rpc-types-compat/src/transaction.rs +++ b/crates/rpc/rpc-types-compat/src/transaction.rs @@ -2,7 +2,8 @@ use crate::fees::{CallFees, CallFeesError}; use alloy_consensus::{ - error::ValueError, transaction::Recovered, EthereumTxEnvelope, SignableTransaction, TxEip4844, + error::ValueError, transaction::Recovered, EthereumTxEnvelope, Extended, SignableTransaction, + Transaction as ConsensusTransaction, TxEip4844, }; use alloy_network::Network; use alloy_primitives::{Address, Bytes, Signature, TxKind, U256}; @@ -94,6 +95,33 @@ pub trait IntoRpcTx { fn into_rpc_tx(self, signer: Address, tx_info: Self::TxInfo) -> T; } +impl IntoRpcTx> for Extended +where + BuiltIn: ConsensusTransaction, + Other: ConsensusTransaction, +{ + type TxInfo = TransactionInfo; + + fn into_rpc_tx(self, signer: Address, tx_info: Self::TxInfo) -> Transaction { + let TransactionInfo { + block_hash, block_number, index: transaction_index, base_fee, .. + } = tx_info; + let effective_gas_price = base_fee + .map(|base_fee| { + self.effective_tip_per_gas(base_fee).unwrap_or_default() + base_fee as u128 + }) + .unwrap_or_else(|| self.max_fee_per_gas()); + + Transaction { + inner: Recovered::new_unchecked(self, signer), + block_hash, + block_number, + transaction_index, + effective_gas_price: Some(effective_gas_price), + } + } +} + /// Converts `self` into `T`. /// /// Should create a fake transaction for simulation using [`TransactionRequest`].