Skip to content

Commit

Permalink
chore: simplify transaction to call request conversion (paradigmxyz#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 29, 2024
1 parent 4649d6f commit 86e383f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
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)
}

0 comments on commit 86e383f

Please sign in to comment.