Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify transaction to call request conversion #13574

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rpc/rpc-types-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 5 additions & 44 deletions crates/rpc/rpc-types-compat/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -68,44 +64,9 @@ pub trait TransactionCompat<T = TransactionSigned>:
}

/// Convert [`RecoveredTx`] to [`TransactionRequest`]
pub fn transaction_to_call_request(tx: RecoveredTx) -> TransactionRequest {
pub fn transaction_to_call_request<T: alloy_consensus::Transaction>(
tx: RecoveredTx<T>,
) -> 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)
}
Loading