Skip to content

Commit 7272b21

Browse files
authored
feat(rpc): Implement IntoRpcTx with Ethereum RPC transaction response for Extended (#16783)
1 parent 8d691ab commit 7272b21

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

crates/rpc/rpc-types-compat/src/transaction.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use crate::fees::{CallFees, CallFeesError};
44
use alloy_consensus::{
5-
error::ValueError, transaction::Recovered, EthereumTxEnvelope, SignableTransaction, TxEip4844,
5+
error::ValueError, transaction::Recovered, EthereumTxEnvelope, Extended, SignableTransaction,
6+
Transaction as ConsensusTransaction, TxEip4844,
67
};
78
use alloy_network::Network;
89
use alloy_primitives::{Address, Bytes, Signature, TxKind, U256};
@@ -94,6 +95,33 @@ pub trait IntoRpcTx<T> {
9495
fn into_rpc_tx(self, signer: Address, tx_info: Self::TxInfo) -> T;
9596
}
9697

98+
impl<BuiltIn, Other> IntoRpcTx<Transaction<Self>> for Extended<BuiltIn, Other>
99+
where
100+
BuiltIn: ConsensusTransaction,
101+
Other: ConsensusTransaction,
102+
{
103+
type TxInfo = TransactionInfo;
104+
105+
fn into_rpc_tx(self, signer: Address, tx_info: Self::TxInfo) -> Transaction<Self> {
106+
let TransactionInfo {
107+
block_hash, block_number, index: transaction_index, base_fee, ..
108+
} = tx_info;
109+
let effective_gas_price = base_fee
110+
.map(|base_fee| {
111+
self.effective_tip_per_gas(base_fee).unwrap_or_default() + base_fee as u128
112+
})
113+
.unwrap_or_else(|| self.max_fee_per_gas());
114+
115+
Transaction {
116+
inner: Recovered::new_unchecked(self, signer),
117+
block_hash,
118+
block_number,
119+
transaction_index,
120+
effective_gas_price: Some(effective_gas_price),
121+
}
122+
}
123+
}
124+
97125
/// Converts `self` into `T`.
98126
///
99127
/// Should create a fake transaction for simulation using [`TransactionRequest`].

0 commit comments

Comments
 (0)