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: rm outdated utils #7616

Merged
merged 1 commit into from
Apr 9, 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
25 changes: 10 additions & 15 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Transaction related types

use crate::eth::{
transaction::optimism::{DepositTransaction, DepositTransactionRequest},
utils::eip_to_revm_access_list,
};
use crate::eth::transaction::optimism::{DepositTransaction, DepositTransactionRequest};
use alloy_consensus::{
AnyReceiptEnvelope, BlobTransactionSidecar, Receipt, ReceiptEnvelope, ReceiptWithBloom, Signed,
TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEip4844WithSidecar, TxEnvelope, TxLegacy,
Expand All @@ -25,8 +22,6 @@ use revm::{
use serde::{Deserialize, Serialize};
use std::ops::Deref;

use super::utils::from_eip_to_alloy_access_list;

pub mod optimism;

/// The signature used to bypass signing via the `eth_sendUnsignedTransaction` cheat RPC
Expand Down Expand Up @@ -393,7 +388,7 @@ pub fn to_alloy_transaction_with_hash_and_sender(
v: U256::from(t.signature().v().y_parity_byte()),
y_parity: Some(alloy_rpc_types::Parity::from(t.signature().v().y_parity())),
}),
access_list: Some(from_eip_to_alloy_access_list(t.tx().tx().access_list.clone())),
access_list: Some(t.tx().tx().access_list.clone()),
transaction_type: Some(3),
max_fee_per_blob_gas: Some(t.tx().tx().max_fee_per_blob_gas),
blob_versioned_hashes: Some(t.tx().tx().blob_versioned_hashes.clone()),
Expand Down Expand Up @@ -482,7 +477,7 @@ impl PendingTransaction {
TxEnv {
caller,
transact_to: transact_to(to),
data: alloy_primitives::Bytes(input.0.clone()),
data: input.clone(),
chain_id,
nonce: Some(*nonce),
value: (*value),
Expand All @@ -508,14 +503,14 @@ impl PendingTransaction {
TxEnv {
caller,
transact_to: transact_to(to),
data: alloy_primitives::Bytes(input.0.clone()),
data: input.clone(),
chain_id: Some(*chain_id),
nonce: Some(*nonce),
value: *value,
gas_price: U256::from(*gas_price),
gas_priority_fee: None,
gas_limit: *gas_limit as u64,
access_list: eip_to_revm_access_list(access_list.0.clone()),
access_list: access_list.flattened(),
..Default::default()
}
}
Expand All @@ -535,14 +530,14 @@ impl PendingTransaction {
TxEnv {
caller,
transact_to: transact_to(to),
data: alloy_primitives::Bytes(input.0.clone()),
data: input.clone(),
chain_id: Some(*chain_id),
nonce: Some(*nonce),
value: *value,
gas_price: U256::from(*max_fee_per_gas),
gas_priority_fee: Some(U256::from(*max_priority_fee_per_gas)),
gas_limit: *gas_limit as u64,
access_list: eip_to_revm_access_list(access_list.0.clone()),
access_list: access_list.flattened(),
..Default::default()
}
}
Expand All @@ -564,7 +559,7 @@ impl PendingTransaction {
TxEnv {
caller,
transact_to: TransactTo::call(*to),
data: alloy_primitives::Bytes(input.0.clone()),
data: input.clone(),
chain_id: Some(*chain_id),
nonce: Some(*nonce),
value: *value,
Expand All @@ -573,7 +568,7 @@ impl PendingTransaction {
max_fee_per_blob_gas: Some(U256::from(*max_fee_per_blob_gas)),
blob_hashes: blob_versioned_hashes.clone(),
gas_limit: *gas_limit as u64,
access_list: eip_to_revm_access_list(access_list.0.clone()),
access_list: access_list.flattened(),
..Default::default()
}
}
Expand All @@ -593,7 +588,7 @@ impl PendingTransaction {
TxEnv {
caller,
transact_to: transact_to(kind),
data: alloy_primitives::Bytes(input.0.clone()),
data: input.clone(),
chain_id,
nonce: Some(*nonce),
value: *value,
Expand Down
33 changes: 1 addition & 32 deletions crates/anvil/core/src/eth/utils.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
use alloy_eips::eip2930::{
AccessList as AlloyEipAccessList, AccessListItem as AlloyEipAccessListItem,
};
use alloy_primitives::{Address, Parity, U256};
use alloy_rpc_types::{AccessList as AlloyAccessList, AccessListItem as AlloyAccessListItem};

pub fn alloy_to_revm_access_list(list: Vec<AlloyAccessListItem>) -> Vec<(Address, Vec<U256>)> {
list.into_iter()
.map(|item| (item.address, item.storage_keys.into_iter().map(|k| k.into()).collect()))
.collect()
}

/// Translates a vec of [AlloyEipAccessListItem] to a [AlloyAccessList], translating from internal
/// type to rpc type.
pub fn from_eip_to_alloy_access_list(list: AlloyEipAccessList) -> AlloyAccessList {
AlloyAccessList(
list.0
.into_iter()
.map(|item| AlloyAccessListItem {
address: item.address,
storage_keys: item.storage_keys.into_iter().collect(),
})
.collect(),
)
}

/// Translates a vec of [AlloyEipAccessListItem] to a revm style Access List.
pub fn eip_to_revm_access_list(list: Vec<AlloyEipAccessListItem>) -> Vec<(Address, Vec<U256>)> {
list.into_iter()
.map(|item| (item.address, item.storage_keys.into_iter().map(|k| k.into()).collect()))
.collect()
}
use alloy_primitives::Parity;

/// See <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md>
/// > If you do, then the v of the signature MUST be set to {0,1} + CHAIN_ID * 2 + 35 where
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use anvil_core::{
DepositReceipt, MaybeImpersonatedTransaction, PendingTransaction, ReceiptResponse,
TransactionInfo, TypedReceipt, TypedTransaction,
},
utils::{alloy_to_revm_access_list, meets_eip155},
utils::meets_eip155,
},
types::{Forking, Index},
};
Expand Down Expand Up @@ -1097,7 +1097,7 @@ impl Backend {
data: input.into_input().unwrap_or_default(),
chain_id: None,
nonce,
access_list: alloy_to_revm_access_list(access_list.unwrap_or_default().0),
access_list: access_list.unwrap_or_default().flattened(),
..Default::default()
};

Expand Down
Loading