diff --git a/Cargo.lock b/Cargo.lock index e50a9085dd536..516aeba762e09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,7 +90,7 @@ dependencies = [ [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-eips", "alloy-network", @@ -122,7 +122,7 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -133,7 +133,7 @@ dependencies = [ [[package]] name = "alloy-genesis" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -155,7 +155,7 @@ dependencies = [ [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-primitives", "serde", @@ -166,7 +166,7 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-eips", "alloy-json-rpc", @@ -205,7 +205,7 @@ dependencies = [ [[package]] name = "alloy-providers" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-network", "alloy-primitives", @@ -224,7 +224,7 @@ dependencies = [ [[package]] name = "alloy-pubsub" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -263,7 +263,7 @@ dependencies = [ [[package]] name = "alloy-rpc-client" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "alloy-rpc-trace-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -291,7 +291,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -304,7 +304,7 @@ dependencies = [ [[package]] name = "alloy-signer" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-network", "alloy-primitives", @@ -365,7 +365,7 @@ dependencies = [ [[package]] name = "alloy-transport" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-json-rpc", "base64 0.21.7", @@ -381,7 +381,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -394,7 +394,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -412,7 +412,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#32618e9243a761858a0843e7e55575e48fdbf500" +source = "git+https://github.com/alloy-rs/alloy#098ad5657d55bbc5fe9469ede2a9ca79def738f2" dependencies = [ "alloy-pubsub", "alloy-transport", diff --git a/crates/anvil/core/src/eth/mod.rs b/crates/anvil/core/src/eth/mod.rs index 4a63675917c98..87c02d9b82990 100644 --- a/crates/anvil/core/src/eth/mod.rs +++ b/crates/anvil/core/src/eth/mod.rs @@ -1,13 +1,14 @@ use crate::{ - eth::{subscription::SubscriptionId, transaction::EthTransactionRequest}, + eth::subscription::SubscriptionId, types::{EvmMineOptions, Forking, Index}, }; use alloy_primitives::{Address, Bytes, TxHash, B256, B64, U256}; use alloy_rpc_trace_types::geth::{GethDebugTracingOptions, GethDefaultTracingOptions}; use alloy_rpc_types::{ pubsub::{Params as SubscriptionParams, SubscriptionKind}, + request::TransactionRequest, state::StateOverride, - BlockId, BlockNumberOrTag as BlockNumber, CallRequest, Filter, + BlockId, BlockNumberOrTag as BlockNumber, Filter, }; pub mod block; @@ -142,7 +143,7 @@ pub enum EthRequest { EthSign(Address, Bytes), #[cfg_attr(feature = "serde", serde(rename = "eth_signTransaction"))] - EthSignTransaction(Box), + EthSignTransaction(Box), /// Signs data via [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md). #[cfg_attr(feature = "serde", serde(rename = "eth_signTypedData"))] @@ -157,27 +158,27 @@ pub enum EthRequest { EthSignTypedDataV4(Address, alloy_dyn_abi::TypedData), #[cfg_attr(feature = "serde", serde(rename = "eth_sendTransaction", with = "sequence"))] - EthSendTransaction(Box), + EthSendTransaction(Box), #[cfg_attr(feature = "serde", serde(rename = "eth_sendRawTransaction", with = "sequence"))] EthSendRawTransaction(Bytes), #[cfg_attr(feature = "serde", serde(rename = "eth_call"))] EthCall( - CallRequest, + TransactionRequest, #[cfg_attr(feature = "serde", serde(default))] Option, #[cfg_attr(feature = "serde", serde(default))] Option, ), #[cfg_attr(feature = "serde", serde(rename = "eth_createAccessList"))] EthCreateAccessList( - CallRequest, + TransactionRequest, #[cfg_attr(feature = "serde", serde(default))] Option, ), #[cfg_attr(feature = "serde", serde(rename = "eth_estimateGas"))] EthEstimateGas( - CallRequest, + TransactionRequest, #[cfg_attr(feature = "serde", serde(default))] Option, #[cfg_attr(feature = "serde", serde(default))] Option, ), @@ -271,7 +272,7 @@ pub enum EthRequest { /// geth's `debug_traceCall` endpoint #[cfg_attr(feature = "serde", serde(rename = "debug_traceCall"))] DebugTraceCall( - CallRequest, + TransactionRequest, #[cfg_attr(feature = "serde", serde(default))] Option, #[cfg_attr(feature = "serde", serde(default))] GethDefaultTracingOptions, ), @@ -596,7 +597,7 @@ pub enum EthRequest { feature = "serde", serde(rename = "eth_sendUnsignedTransaction", with = "sequence") )] - EthSendUnsignedTransaction(Box), + EthSendUnsignedTransaction(Box), /// Turn on call traces for transactions that are returned to the user when they execute a /// transaction (instead of just txhash/receipt) @@ -1451,7 +1452,7 @@ true}]}"#; #[test] fn test_eth_call() { let req = r#"{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"}"#; - let _req = serde_json::from_str::(req).unwrap(); + let _req = serde_json::from_str::(req).unwrap(); let s = r#"{"method": "eth_call", "params":[{"data":"0xcfae3217","from":"0xd84de507f3fada7df80908082d3239466db55a71","to":"0xcbe828fdc46e3b1c351ec90b1a5e7d9742c0398d"},"latest"]}"#; let _req = serde_json::from_str::(s).unwrap(); diff --git a/crates/anvil/core/src/eth/transaction/mod.rs b/crates/anvil/core/src/eth/transaction/mod.rs index 5582ca80df340..502cd075dafff 100644 --- a/crates/anvil/core/src/eth/transaction/mod.rs +++ b/crates/anvil/core/src/eth/transaction/mod.rs @@ -9,8 +9,8 @@ use alloy_network::{Signed, Transaction, TxKind}; use alloy_primitives::{Address, Bloom, Bytes, Log, Signature, TxHash, B256, U128, U256, U64}; use alloy_rlp::{Decodable, Encodable}; use alloy_rpc_types::{ - request::TransactionRequest, AccessList, AccessListItem, CallInput, CallRequest, - Signature as RpcSignature, Transaction as RpcTransaction, + request::TransactionRequest, AccessList, Signature as RpcSignature, + Transaction as RpcTransaction, }; use foundry_evm::traces::CallTraceNode; use revm::{ @@ -30,199 +30,8 @@ pub fn impersonated_signature() -> Signature { .unwrap() } -/// Represents _all_ transaction requests received from RPC -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(deny_unknown_fields))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] -pub struct EthTransactionRequest { - /// from address - pub from: Option
, - /// to address - pub to: Option
, - /// legacy, gas Price - #[cfg_attr(feature = "serde", serde(default))] - pub gas_price: Option, - /// max base fee per gas sender is willing to pay - #[cfg_attr(feature = "serde", serde(default))] - pub max_fee_per_gas: Option, - /// miner tip - #[cfg_attr(feature = "serde", serde(default))] - pub max_priority_fee_per_gas: Option, - /// gas - pub gas: Option, - /// value of th tx in wei - pub value: Option, - /// Any additional data sent - #[cfg_attr(feature = "serde", serde(alias = "input"))] - pub data: Option, - /// Transaction nonce - pub nonce: Option, - /// chain id - #[cfg_attr(feature = "serde", serde(default))] - pub chain_id: Option, - /// warm storage access pre-payment - #[cfg_attr(feature = "serde", serde(default))] - pub access_list: Option>, - /// EIP-2718 type - #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub transaction_type: Option, - /// Optimism Deposit Request Fields - #[serde(flatten)] - pub optimism_fields: Option, -} - -impl EthTransactionRequest { - pub fn into_call_request(self) -> CallRequest { - let Self { - from, - to, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - gas, - value, - data, - nonce, - chain_id, - access_list, - transaction_type, - optimism_fields: _, - } = self; - CallRequest { - from, - to, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - gas, - value, - input: CallInput::maybe_input(data), - nonce: nonce.map(|n| n.to()), - chain_id, - access_list: access_list.map(AccessList), - max_fee_per_blob_gas: None, - blob_versioned_hashes: None, - transaction_type: transaction_type.map(|ty| ty.to()), - } - } -} - -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(deny_unknown_fields))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] -pub struct OptimismDepositRequestFields { - /// op-stack deposit source hash - pub source_hash: B256, - /// op-stack deposit mint - pub mint: U256, - /// op-stack deposit system tx - pub is_system_tx: bool, -} - -impl EthTransactionRequest { - pub fn into_typed_request(self) -> Option { - let EthTransactionRequest { - from, - to, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - gas, - value, - data, - nonce, - mut access_list, - transaction_type, - optimism_fields, - .. - } = self; - let transaction_type = transaction_type.map(|id| id.to::()); - let data = data.clone().unwrap_or_default(); - // Special case: OP-stack deposit tx - if transaction_type == Some(126) { - return Some(TypedTransactionRequest::Deposit(DepositTransactionRequest { - from: from.unwrap_or_default(), - source_hash: optimism_fields.clone()?.source_hash, - kind: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - mint: optimism_fields.clone()?.mint, - value: value.unwrap_or_default(), - gas_limit: gas.unwrap_or_default(), - is_system_tx: optimism_fields.clone()?.is_system_tx, - input: data, - })) - } - - match ( - transaction_type, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - access_list.take(), - ) { - // legacy transaction - (Some(0), _, None, None, None) | (None, Some(_), None, None, None) => { - Some(TypedTransactionRequest::Legacy(TxLegacy { - nonce: nonce.unwrap_or_default().to::(), - gas_price: gas_price.unwrap_or_default().to::(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: data, - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id: None, - })) - } - // EIP2930 - (Some(1), _, None, None, _) | (None, _, None, None, Some(_)) => { - Some(TypedTransactionRequest::EIP2930(TxEip2930 { - nonce: nonce.unwrap_or_default().to::(), - gas_price: gas_price.unwrap_or_default().to(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: data, - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id: 0, - access_list: to_eip_access_list(AccessList(access_list.unwrap_or_default())), - })) - } - // EIP1559 - (Some(2), None, _, _, _) | - (None, None, Some(_), _, _) | - (None, None, _, Some(_), _) | - (None, None, None, None, None) => { - // Empty fields fall back to the canonical transaction schema. - Some(TypedTransactionRequest::EIP1559(TxEip1559 { - nonce: nonce.unwrap_or_default().to::(), - max_fee_per_gas: max_fee_per_gas.unwrap_or_default().to::(), - max_priority_fee_per_gas: max_priority_fee_per_gas - .unwrap_or_default() - .to::(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: data, - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id: 0, - access_list: to_eip_access_list(AccessList(access_list.unwrap_or_default())), - })) - } - _ => None, - } - } -} - +/// Converts a [TransactionRequest] into a [TypedTransactionRequest]. +/// Should be removed once the call builder abstraction for providers is in place. pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option { let TransactionRequest { from, @@ -232,7 +41,7 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option Option("sourceHash")?.ok()?, - kind: TxKind::Create, + kind: to.into(), mint: other.get_deserialized::("mint")?.ok()?, value: value.unwrap_or_default(), gas_limit: gas.unwrap_or_default(), is_system_tx: other.get_deserialized::("isSystemTx")?.ok()?, - input: data.unwrap_or_default(), + input: input.into_input().unwrap_or_default(), })) } @@ -269,7 +78,7 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option(), gas_limit: gas.unwrap_or_default().to::(), value: value.unwrap_or(U256::ZERO), - input: data.unwrap_or_default(), + input: input.into_input().unwrap_or_default(), to: match to { Some(to) => TxKind::Call(to), None => TxKind::Create, @@ -284,7 +93,7 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option(), value: value.unwrap_or(U256::ZERO), - input: data.unwrap_or_default(), + input: input.into_input().unwrap_or_default(), to: match to { Some(to) => TxKind::Call(to), None => TxKind::Create, @@ -305,7 +114,7 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option(), gas_limit: gas.unwrap_or_default().to::(), value: value.unwrap_or(U256::ZERO), - input: data.unwrap_or_default(), + input: input.into_input().unwrap_or_default(), to: match to { Some(to) => TxKind::Call(to), None => TxKind::Create, @@ -318,87 +127,6 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option Option { - let CallRequest { - to, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - gas, - value, - input, - chain_id, - nonce, - mut access_list, - transaction_type, - .. - } = tx; - let chain_id = chain_id.map(|id| id.to::()); - let transaction_type = transaction_type.map(|id| id.to::()); - - match ( - transaction_type, - gas_price, - max_fee_per_gas, - max_priority_fee_per_gas, - access_list.take(), - ) { - // legacy transaction - (Some(0), _, None, None, None) | (None, Some(_), None, None, None) => { - Some(TypedTransactionRequest::Legacy(TxLegacy { - nonce: nonce.unwrap_or_default().to::(), - gas_price: gas_price.unwrap_or_default().to::(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: input.try_into_unique_input().unwrap_or_default().unwrap_or_default(), - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id, - })) - } - // EIP2930 - (Some(1), _, None, None, _) | (None, _, None, None, Some(_)) => { - Some(TypedTransactionRequest::EIP2930(TxEip2930 { - nonce: nonce.unwrap_or_default().to::(), - gas_price: gas_price.unwrap_or_default().to(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: input.try_into_unique_input().unwrap_or_default().unwrap_or_default(), - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id: chain_id.unwrap_or_default(), - access_list: to_eip_access_list(access_list.unwrap_or_default()), - })) - } - // EIP1559 - (Some(2), None, _, _, _) | - (None, None, Some(_), _, _) | - (None, None, _, Some(_), _) | - (None, None, None, None, None) => { - // Empty fields fall back to the canonical transaction schema. - Some(TypedTransactionRequest::EIP1559(TxEip1559 { - nonce: nonce.unwrap_or_default().to::(), - max_fee_per_gas: max_fee_per_gas.unwrap_or_default().to::(), - max_priority_fee_per_gas: max_priority_fee_per_gas.unwrap_or_default().to::(), - gas_limit: gas.unwrap_or_default().to::(), - value: value.unwrap_or(U256::ZERO), - input: input.try_into_unique_input().unwrap_or_default().unwrap_or_default(), - to: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, - chain_id: chain_id.unwrap_or_default(), - access_list: to_eip_access_list(access_list.unwrap_or_default()), - })) - } - _ => None, - } -} - #[derive(Clone, Debug, PartialEq, Eq)] pub enum TypedTransactionRequest { Legacy(TxLegacy), diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index e796e4f4dde7c..fff26c9d9ffb4 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -41,18 +41,19 @@ use alloy_rpc_trace_types::{ parity::LocalizedTransactionTrace, }; use alloy_rpc_types::{ + request::TransactionRequest, state::StateOverride, txpool::{TxpoolContent, TxpoolInspect, TxpoolInspectSummary, TxpoolStatus}, AccessList, AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag as BlockNumber, - BlockTransactions, CallRequest, EIP1186AccountProofResponse, FeeHistory, Filter, - FilteredParams, Log, Transaction, TransactionReceipt, + BlockTransactions, EIP1186AccountProofResponse, FeeHistory, Filter, FilteredParams, Log, + Transaction, TransactionReceipt, }; use alloy_transport::TransportErrorKind; use anvil_core::{ eth::{ block::BlockInfo, transaction::{ - call_request_to_typed, EthTransactionRequest, PendingTransaction, TypedTransaction, + transaction_request_to_typed, PendingTransaction, TypedTransaction, TypedTransactionRequest, }, EthRequest, @@ -852,7 +853,7 @@ impl EthApi { /// Signs a transaction /// /// Handler for ETH RPC call: `eth_signTransaction` - pub async fn sign_transaction(&self, mut request: EthTransactionRequest) -> Result { + pub async fn sign_transaction(&self, mut request: TransactionRequest) -> Result { node_info!("eth_signTransaction"); let from = request.from.map(Ok).unwrap_or_else(|| { @@ -863,9 +864,7 @@ impl EthApi { if request.gas.is_none() { // estimate if not provided - if let Ok(gas) = - self.estimate_gas(request.clone().into_call_request(), None, None).await - { + if let Ok(gas) = self.estimate_gas(request.clone(), None, None).await { request.gas = Some(gas); } } @@ -881,7 +880,7 @@ impl EthApi { /// Sends a transaction /// /// Handler for ETH RPC call: `eth_sendTransaction` - pub async fn send_transaction(&self, mut request: EthTransactionRequest) -> Result { + pub async fn send_transaction(&self, mut request: TransactionRequest) -> Result { node_info!("eth_sendTransaction"); let from = request.from.map(Ok).unwrap_or_else(|| { @@ -891,9 +890,7 @@ impl EthApi { if request.gas.is_none() { // estimate if not provided - if let Ok(gas) = - self.estimate_gas(request.clone().into_call_request(), None, None).await - { + if let Ok(gas) = self.estimate_gas(request.clone(), None, None).await { request.gas = Some(gas); } } @@ -978,7 +975,7 @@ impl EthApi { /// Handler for ETH RPC call: `eth_call` pub async fn call( &self, - request: CallRequest, + request: TransactionRequest, block_number: Option, overrides: Option, ) -> Result { @@ -1034,7 +1031,7 @@ impl EthApi { /// Handler for ETH RPC call: `eth_createAccessList` pub async fn create_access_list( &self, - mut request: CallRequest, + mut request: TransactionRequest, block_number: Option, ) -> Result { node_info!("eth_createAccessList"); @@ -1086,7 +1083,7 @@ impl EthApi { /// Handler for ETH RPC call: `eth_estimateGas` pub async fn estimate_gas( &self, - request: CallRequest, + request: TransactionRequest, block_number: Option, overrides: Option, ) -> Result { @@ -1314,6 +1311,8 @@ impl EthApi { base_fee_per_gas: Vec::new(), gas_used_ratio: Vec::new(), reward: Some(Default::default()), + base_fee_per_blob_gas: Default::default(), + blob_gas_used_ratio: Default::default(), }; let mut rewards = Vec::new(); @@ -1463,7 +1462,7 @@ impl EthApi { /// Handler for RPC call: `debug_traceCall` pub async fn debug_trace_call( &self, - request: CallRequest, + request: TransactionRequest, block_number: Option, opts: GethDefaultTracingOptions, ) -> Result { @@ -1988,7 +1987,7 @@ impl EthApi { /// Handler for ETH RPC call: `eth_sendUnsignedTransaction` pub async fn eth_send_unsigned_transaction( &self, - request: EthTransactionRequest, + request: TransactionRequest, ) -> Result { node_info!("eth_sendUnsignedTransaction"); // either use the impersonated account of the request's `from` field @@ -2154,7 +2153,7 @@ impl EthApi { async fn do_estimate_gas( &self, - request: CallRequest, + request: TransactionRequest, block_number: Option, overrides: Option, ) -> Result { @@ -2194,7 +2193,7 @@ impl EthApi { /// This will execute the [CallRequest] and find the best gas limit via binary search fn do_estimate_gas_with_state( &self, - mut request: CallRequest, + mut request: TransactionRequest, state: D, block_env: BlockEnv, ) -> Result @@ -2488,7 +2487,7 @@ impl EthApi { fn build_typed_tx_request( &self, - request: EthTransactionRequest, + request: TransactionRequest, nonce: U256, ) -> Result { let chain_id = request.chain_id.map(|c| c.to::()).unwrap_or_else(|| self.chain_id()); @@ -2497,7 +2496,7 @@ impl EthApi { let gas_limit = request.gas.map(Ok).unwrap_or_else(|| self.current_gas_limit())?; - let request = match request.into_typed_request() { + let request = match transaction_request_to_typed(request) { Some(TypedTransactionRequest::Legacy(mut m)) => { m.nonce = nonce.to::(); m.chain_id = Some(chain_id); @@ -2572,12 +2571,12 @@ impl EthApi { /// This will also check the tx pool for pending transactions from the sender. async fn request_nonce( &self, - request: &EthTransactionRequest, + request: &TransactionRequest, from: Address, ) -> Result<(U256, U256)> { let highest_nonce = self.get_transaction_count(from, Some(BlockId::Number(BlockNumber::Pending))).await?; - let nonce = request.nonce.unwrap_or(highest_nonce); + let nonce = request.nonce.map(|n| n.to::()).unwrap_or(highest_nonce); Ok((nonce, highest_nonce)) } @@ -2648,7 +2647,7 @@ fn ensure_return_ok(exit: InstructionResult, out: &Option) -> Result( - mut request: CallRequest, + mut request: TransactionRequest, state: D, backend: Arc, block_env: BlockEnv, @@ -2682,8 +2681,8 @@ where /// Determines the minimum gas needed for a transaction depending on the transaction kind. #[inline] -fn determine_base_gas_by_kind(request: &CallRequest) -> U256 { - match call_request_to_typed(request.clone()) { +fn determine_base_gas_by_kind(request: &TransactionRequest) -> U256 { + match transaction_request_to_typed(request.clone()) { Some(request) => match request { TypedTransactionRequest::Legacy(req) => match req.to { TxKind::Call(_) => MIN_TRANSACTION_GAS, diff --git a/crates/anvil/src/eth/backend/fork.rs b/crates/anvil/src/eth/backend/fork.rs index 75312b6a63bb9..baf177e25b629 100644 --- a/crates/anvil/src/eth/backend/fork.rs +++ b/crates/anvil/src/eth/backend/fork.rs @@ -8,9 +8,9 @@ use alloy_rpc_trace_types::{ parity::LocalizedTransactionTrace as Trace, }; use alloy_rpc_types::{ - AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag as BlockNumber, BlockTransactions, - CallRequest, EIP1186AccountProofResponse, FeeHistory, Filter, Log, Transaction, - TransactionReceipt, + request::TransactionRequest, AccessListWithGasUsed, Block, BlockId, + BlockNumberOrTag as BlockNumber, BlockTransactions, EIP1186AccountProofResponse, FeeHistory, + Filter, Log, Transaction, TransactionReceipt, }; use alloy_transport::TransportError; use foundry_common::provider::alloy::{ProviderBuilder, RetryProvider}; @@ -169,7 +169,7 @@ impl ClientFork { /// Sends `eth_call` pub async fn call( &self, - request: &CallRequest, + request: &TransactionRequest, block: Option, ) -> Result { let request = Arc::new(request.clone()); @@ -199,7 +199,7 @@ impl ClientFork { /// Sends `eth_call` pub async fn estimate_gas( &self, - request: &CallRequest, + request: &TransactionRequest, block: Option, ) -> Result { let request = Arc::new(request.clone()); @@ -229,7 +229,7 @@ impl ClientFork { /// Sends `eth_createAccessList` pub async fn create_access_list( &self, - request: &CallRequest, + request: &TransactionRequest, block: Option, ) -> Result { self.provider().create_access_list(request.clone(), block.map(|b| b.into())).await @@ -674,8 +674,8 @@ pub struct ForkedStorage { pub geth_transaction_traces: HashMap, pub block_traces: HashMap>, pub block_receipts: HashMap>, - pub eth_gas_estimations: HashMap<(Arc, u64), U256>, - pub eth_call: HashMap<(Arc, u64), Bytes>, + pub eth_gas_estimations: HashMap<(Arc, u64), U256>, + pub eth_call: HashMap<(Arc, u64), Bytes>, pub code_at: HashMap<(Address, u64), Bytes>, } diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index f95b6b96ee9a3..da599966bc068 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -38,8 +38,8 @@ use alloy_rpc_trace_types::{ parity::LocalizedTransactionTrace, }; use alloy_rpc_types::{ - state::StateOverride, AccessList, Block as AlloyBlock, BlockId, - BlockNumberOrTag as BlockNumber, CallRequest, EIP1186AccountProofResponse as AccountProof, + request::TransactionRequest, state::StateOverride, AccessList, Block as AlloyBlock, BlockId, + BlockNumberOrTag as BlockNumber, EIP1186AccountProofResponse as AccountProof, EIP1186StorageProof as StorageProof, Filter, FilteredParams, Header as AlloyHeader, Log, Transaction, TransactionReceipt, }; @@ -1015,14 +1015,14 @@ impl Backend { outcome } - /// Executes the [CallRequest] without writing to the DB + /// Executes the [TransactionRequest] without writing to the DB /// /// # Errors /// /// Returns an error if the `block_number` is greater than the current height pub async fn call( &self, - request: CallRequest, + request: TransactionRequest, fee_details: FeeDetails, block_request: Option, overrides: Option, @@ -1043,11 +1043,11 @@ impl Backend { fn build_call_env( &self, - request: CallRequest, + request: TransactionRequest, fee_details: FeeDetails, block_env: BlockEnv, ) -> Env { - let CallRequest { from, to, gas, value, input, nonce, access_list, .. } = request; + let TransactionRequest { from, to, gas, value, input, nonce, access_list, .. } = request; let FeeDetails { gas_price, max_fee_per_gas, max_priority_fee_per_gas } = fee_details; @@ -1094,7 +1094,7 @@ impl Backend { pub fn call_with_state( &self, state: D, - request: CallRequest, + request: TransactionRequest, fee_details: FeeDetails, block_env: BlockEnv, ) -> Result<(InstructionResult, Option, u64, State), BlockchainError> @@ -1140,7 +1140,7 @@ impl Backend { pub async fn call_with_tracing( &self, - request: CallRequest, + request: TransactionRequest, fee_details: FeeDetails, block_request: Option, opts: GethDefaultTracingOptions, @@ -1180,7 +1180,7 @@ impl Backend { pub fn build_access_list_with_state( &self, state: D, - request: CallRequest, + request: TransactionRequest, fee_details: FeeDetails, block_env: BlockEnv, ) -> Result<(InstructionResult, Option, u64, AccessList), BlockchainError> diff --git a/crates/anvil/tests/it/api.rs b/crates/anvil/tests/it/api.rs index 50a239b48a25c..fb3c3742b2e62 100644 --- a/crates/anvil/tests/it/api.rs +++ b/crates/anvil/tests/it/api.rs @@ -7,8 +7,8 @@ use crate::{ use alloy_primitives::{Address as rAddress, B256, U256 as rU256}; use alloy_providers::provider::TempProvider; use alloy_rpc_types::{ + request::{TransactionInput as CallInput, TransactionRequest as CallRequest}, state::{AccountOverride, StateOverride}, - CallInput, CallRequest, }; use alloy_signer::Signer as AlloySigner; use anvil::{ diff --git a/crates/anvil/tests/it/fork.rs b/crates/anvil/tests/it/fork.rs index d0f60d5e941b7..0bd6f7dcb78ed 100644 --- a/crates/anvil/tests/it/fork.rs +++ b/crates/anvil/tests/it/fork.rs @@ -6,7 +6,7 @@ use crate::{ }; use alloy_primitives::U256 as rU256; use alloy_providers::provider::TempProvider; -use alloy_rpc_types::{BlockNumberOrTag, CallRequest}; +use alloy_rpc_types::{request::TransactionRequest as CallRequest, BlockNumberOrTag}; use alloy_signer::Signer as AlloySigner; use anvil::{eth::EthApi, spawn, NodeConfig, NodeHandle}; use anvil_core::types::Forking; diff --git a/crates/anvil/tests/it/transaction.rs b/crates/anvil/tests/it/transaction.rs index fd8dee363d694..18a74e1a9d8ae 100644 --- a/crates/anvil/tests/it/transaction.rs +++ b/crates/anvil/tests/it/transaction.rs @@ -4,12 +4,12 @@ use crate::{ }; use alloy_primitives::U256 as rU256; use alloy_rpc_types::{ + request::TransactionRequest as AlloyTransactionRequest, state::{AccountOverride, StateOverride}, BlockNumberOrTag, }; use alloy_signer::Signer as AlloySigner; use anvil::{spawn, Hardfork, NodeConfig}; -use anvil_core::eth::transaction::EthTransactionRequest; use ethers::{ abi::ethereum_types::BigEndianHash, prelude::{ @@ -1088,7 +1088,7 @@ async fn can_mine_multiple_in_block() { // disable auto mine api.anvil_set_auto_mine(false).await.unwrap(); - let tx = EthTransactionRequest { + let tx = AlloyTransactionRequest { from: Some("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266".parse().unwrap()), ..Default::default() }; diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 4e48c5e9e28d3..8290b9b951de9 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -15,7 +15,7 @@ use crate::{ CheatsConfig, CheatsCtxt, Error, Result, Vm, }; use alloy_primitives::{Address, Bytes, B256, U256, U64}; -use alloy_rpc_types::request::TransactionRequest; +use alloy_rpc_types::request::{TransactionInput, TransactionRequest}; use alloy_signer::LocalWallet; use alloy_sol_types::{SolInterface, SolValue}; use foundry_common::{evm::Breakpoints, provider::alloy::RpcUrl}; @@ -836,7 +836,7 @@ impl Inspector for Cheatcodes { from: Some(broadcast.new_origin), to: Some(call.contract), value: Some(call.transfer.value), - data: Some(call.input.clone()), + input: TransactionInput::new(call.input.clone()), nonce: Some(U64::from(account.info.nonce)), gas: if is_fixed_gas_limit { Some(U256::from(call.gas_limit)) @@ -1222,7 +1222,7 @@ impl Inspector for Cheatcodes { from: Some(broadcast.new_origin), to, value: Some(call.value), - data: Some(bytecode), + input: TransactionInput::new(bytecode), nonce: Some(U64::from(nonce)), gas: if is_fixed_gas_limit { Some(U256::from(call.gas_limit)) diff --git a/crates/common/src/types.rs b/crates/common/src/types.rs index aea3bf6319bc8..2917d92edd6e2 100644 --- a/crates/common/src/types.rs +++ b/crates/common/src/types.rs @@ -2,7 +2,11 @@ use alloy_json_abi::{Event, EventParam, Function, InternalType, Param, StateMutability}; use alloy_primitives::{Address, Bloom, Bytes, B256, B64, I256, U128, U256, U64}; -use alloy_rpc_types::{AccessList, AccessListItem, CallInput, CallRequest, Signature, Transaction}; +use alloy_rpc_types::{ + other::OtherFields, + request::{TransactionInput, TransactionRequest as CallRequest}, + AccessList, AccessListItem, Signature, Transaction, +}; use alloy_signer::{LocalWallet, Signer}; use ethers_core::{ abi as ethabi, @@ -177,13 +181,15 @@ pub fn to_call_request_from_tx_request(tx: TransactionRequest) -> CallRequest { max_priority_fee_per_gas: None, gas: tx.gas.map(|g| g.to_alloy()), value: tx.value.map(|v| v.to_alloy()), - input: CallInput::maybe_input(tx.data.map(|b| b.0.into())), + input: TransactionInput::maybe_input(tx.data.map(|b| b.0.into())), nonce: tx.nonce.map(|n| U64::from(n.as_u64())), chain_id: tx.chain_id.map(|c| c.to_alloy()), access_list: None, max_fee_per_blob_gas: None, blob_versioned_hashes: None, transaction_type: None, + sidecar: None, + other: OtherFields::default(), } } diff --git a/crates/forge/bin/cmd/script/executor.rs b/crates/forge/bin/cmd/script/executor.rs index bea7af8cb2c76..c77c4c1a826d7 100644 --- a/crates/forge/bin/cmd/script/executor.rs +++ b/crates/forge/bin/cmd/script/executor.rs @@ -143,7 +143,7 @@ impl ScriptArgs { tx.from .expect("transaction doesn't have a `from` address at execution time"), tx.to, - tx.data.clone(), + tx.input.clone().into_input(), tx.value, ) .wrap_err("Internal EVM error during simulation")?; diff --git a/crates/forge/bin/cmd/script/mod.rs b/crates/forge/bin/cmd/script/mod.rs index ede0b19fd388a..50ae7481ad864 100644 --- a/crates/forge/bin/cmd/script/mod.rs +++ b/crates/forge/bin/cmd/script/mod.rs @@ -415,7 +415,7 @@ impl ScriptArgs { rpc: fork_url.clone(), transaction: TransactionRequest { from: Some(from), - data: Some(bytes.clone()), + input: Some(bytes.clone()).into(), nonce: Some(U64::from(nonce + i as u64)), ..Default::default() }, @@ -510,8 +510,9 @@ impl ScriptArgs { for (data, to) in result.transactions.iter().flat_map(|txes| { txes.iter().filter_map(|tx| { tx.transaction - .data + .input .clone() + .into_input() .filter(|data| data.len() > max_size) .map(|data| (data, tx.transaction.to)) }) diff --git a/crates/forge/bin/cmd/script/transaction.rs b/crates/forge/bin/cmd/script/transaction.rs index 4568ad357cbcd..fec73b22f001e 100644 --- a/crates/forge/bin/cmd/script/transaction.rs +++ b/crates/forge/bin/cmd/script/transaction.rs @@ -69,7 +69,7 @@ impl TransactionWithMetadata { from: transaction.from.map(ToEthers::to_ethers), to: transaction.to.map(ToEthers::to_ethers).map(Into::into), value: transaction.value.map(ToEthers::to_ethers), - data: transaction.data.map(ToEthers::to_ethers), + data: transaction.input.into_input().map(ToEthers::to_ethers), nonce: transaction.nonce.map(|n| n.to::().into()), gas: transaction.gas.map(ToEthers::to_ethers), ..Default::default()