From 86e383f50760d97470f27607de0dc6938523b4eb Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 29 Dec 2024 14:32:27 +0100 Subject: [PATCH] chore: simplify transaction to call request conversion (#13574) --- crates/rpc/rpc-types-compat/Cargo.toml | 1 + .../rpc/rpc-types-compat/src/transaction.rs | 49 ++----------------- 2 files changed, 6 insertions(+), 44 deletions(-) diff --git a/crates/rpc/rpc-types-compat/Cargo.toml b/crates/rpc/rpc-types-compat/Cargo.toml index d4e1aac88bff..8a6ee44e7cf7 100644 --- a/crates/rpc/rpc-types-compat/Cargo.toml +++ b/crates/rpc/rpc-types-compat/Cargo.toml @@ -29,4 +29,5 @@ serde.workspace = true jsonrpsee-types.workspace = true [dev-dependencies] +alloy-rpc-types-engine = { workspace = true, features = ["serde"] } serde_json.workspace = true diff --git a/crates/rpc/rpc-types-compat/src/transaction.rs b/crates/rpc/rpc-types-compat/src/transaction.rs index d3d1a71decc3..b5515ce9e23d 100644 --- a/crates/rpc/rpc-types-compat/src/transaction.rs +++ b/crates/rpc/rpc-types-compat/src/transaction.rs @@ -3,11 +3,7 @@ use core::error; use std::fmt; -use alloy_consensus::Transaction as _; -use alloy_rpc_types_eth::{ - request::{TransactionInput, TransactionRequest}, - TransactionInfo, -}; +use alloy_rpc_types_eth::{request::TransactionRequest, TransactionInfo}; use reth_primitives::{RecoveredTx, TransactionSigned}; use serde::{Deserialize, Serialize}; @@ -68,44 +64,9 @@ pub trait TransactionCompat: } /// Convert [`RecoveredTx`] to [`TransactionRequest`] -pub fn transaction_to_call_request(tx: RecoveredTx) -> TransactionRequest { +pub fn transaction_to_call_request( + tx: RecoveredTx, +) -> TransactionRequest { let from = tx.signer(); - let to = Some(tx.transaction.to().into()); - let gas = tx.transaction.gas_limit(); - let value = tx.transaction.value(); - let input = tx.transaction.input().clone(); - let nonce = tx.transaction.nonce(); - let chain_id = tx.transaction.chain_id(); - let access_list = tx.transaction.access_list().cloned(); - let max_fee_per_blob_gas = tx.transaction.max_fee_per_blob_gas(); - let authorization_list = tx.transaction.authorization_list().map(|l| l.to_vec()); - let blob_versioned_hashes = tx.transaction.blob_versioned_hashes().map(Vec::from); - let tx_type = tx.transaction.tx_type(); - - // fees depending on the transaction type - let (gas_price, max_fee_per_gas) = if tx.is_dynamic_fee() { - (None, Some(tx.max_fee_per_gas())) - } else { - (Some(tx.max_fee_per_gas()), None) - }; - let max_priority_fee_per_gas = tx.transaction.max_priority_fee_per_gas(); - - TransactionRequest { - from: Some(from), - to, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - gas: Some(gas), - value: Some(value), - input: TransactionInput::new(input), - nonce: Some(nonce), - chain_id, - access_list, - max_fee_per_blob_gas, - blob_versioned_hashes, - transaction_type: Some(tx_type.into()), - sidecar: None, - authorization_list, - } + TransactionRequest::from_transaction_with_sender(tx.into_signed(), from) }