mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: simplify transaction to call request conversion (#13574)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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<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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user