mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove duplicated functions (#12804)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2759,6 +2759,7 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||
name = "example-beacon-api-sidecar-fetcher"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"alloy-consensus",
|
||||
"alloy-primitives",
|
||||
"alloy-rpc-types-beacon",
|
||||
"clap",
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
use crate::OpBlockExecutionError;
|
||||
use alloc::{string::ToString, sync::Arc};
|
||||
use alloy_consensus::Transaction;
|
||||
use alloy_primitives::{address, b256, hex, Address, Bytes, B256, U256};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_execution_errors::BlockExecutionError;
|
||||
|
||||
@ -219,29 +219,6 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the transaction's [`TxKind`], which is the address of the recipient or
|
||||
/// [`TxKind::Create`] if the transaction is a contract creation.
|
||||
pub const fn kind(&self) -> TxKind {
|
||||
match self {
|
||||
Self::Legacy(TxLegacy { to, .. }) |
|
||||
Self::Eip2930(TxEip2930 { to, .. }) |
|
||||
Self::Eip1559(TxEip1559 { to, .. }) => *to,
|
||||
Self::Eip4844(TxEip4844 { to, .. }) | Self::Eip7702(TxEip7702 { to, .. }) => {
|
||||
TxKind::Call(*to)
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit(TxDeposit { to, .. }) => *to,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the transaction's address of the contract that will be called, or the address that will
|
||||
/// receive the transfer.
|
||||
///
|
||||
/// Returns `None` if this is a `CREATE` transaction.
|
||||
pub fn to(&self) -> Option<Address> {
|
||||
self.kind().to().copied()
|
||||
}
|
||||
|
||||
/// Get the transaction's type
|
||||
pub const fn tx_type(&self) -> TxType {
|
||||
match self {
|
||||
@ -255,56 +232,6 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [`AccessList`] of the transaction.
|
||||
///
|
||||
/// Returns `None` for legacy transactions.
|
||||
pub const fn access_list(&self) -> Option<&AccessList> {
|
||||
match self {
|
||||
Self::Legacy(_) => None,
|
||||
Self::Eip2930(tx) => Some(&tx.access_list),
|
||||
Self::Eip1559(tx) => Some(&tx.access_list),
|
||||
Self::Eip4844(tx) => Some(&tx.access_list),
|
||||
Self::Eip7702(tx) => Some(&tx.access_list),
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [`SignedAuthorization`] list of the transaction.
|
||||
///
|
||||
/// Returns `None` if this transaction is not EIP-7702.
|
||||
pub fn authorization_list(&self) -> Option<&[SignedAuthorization]> {
|
||||
match self {
|
||||
Self::Eip7702(tx) => Some(&tx.authorization_list),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the tx supports dynamic fees
|
||||
pub const fn is_dynamic_fee(&self) -> bool {
|
||||
match self {
|
||||
Self::Legacy(_) | Self::Eip2930(_) => false,
|
||||
Self::Eip1559(_) | Self::Eip4844(_) | Self::Eip7702(_) => true,
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Blob versioned hashes for eip4844 transaction, for legacy, eip1559, eip2930 and eip7702
|
||||
/// transactions this is `None`
|
||||
///
|
||||
/// This is also commonly referred to as the "blob versioned hashes" (`BlobVersionedHashes`).
|
||||
pub fn blob_versioned_hashes(&self) -> Option<Vec<B256>> {
|
||||
match self {
|
||||
Self::Legacy(_) | Self::Eip2930(_) | Self::Eip1559(_) | Self::Eip7702(_) => None,
|
||||
Self::Eip4844(TxEip4844 { blob_versioned_hashes, .. }) => {
|
||||
Some(blob_versioned_hashes.clone())
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the blob gas used for all blobs of the EIP-4844 transaction if it is an EIP-4844
|
||||
/// transaction.
|
||||
///
|
||||
@ -345,19 +272,6 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the transaction's input field.
|
||||
pub const fn input(&self) -> &Bytes {
|
||||
match self {
|
||||
Self::Legacy(TxLegacy { input, .. }) |
|
||||
Self::Eip2930(TxEip2930 { input, .. }) |
|
||||
Self::Eip1559(TxEip1559 { input, .. }) |
|
||||
Self::Eip4844(TxEip4844 { input, .. }) |
|
||||
Self::Eip7702(TxEip7702 { input, .. }) => input,
|
||||
#[cfg(feature = "optimism")]
|
||||
Self::Deposit(TxDeposit { input, .. }) => input,
|
||||
}
|
||||
}
|
||||
|
||||
/// This encodes the transaction _without_ the signature, and is only suitable for creating a
|
||||
/// hash intended for signing.
|
||||
pub fn encode_for_signing(&self, out: &mut dyn bytes::BufMut) {
|
||||
@ -2097,13 +2011,15 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
tx.blob_versioned_hashes(),
|
||||
Some(vec![
|
||||
Some(
|
||||
&[
|
||||
b256!("012ec3d6f66766bedb002a190126b3549fce0047de0d4c25cffce0dc1c57921a"),
|
||||
b256!("0152d8e24762ff22b1cfd9f8c0683786a7ca63ba49973818b3d1e9512cd2cec4"),
|
||||
b256!("013b98c6c83e066d5b14af2b85199e3d4fc7d1e778dd53130d180f5077e2d1c7"),
|
||||
b256!("01148b495d6e859114e670ca54fb6e2657f0cbae5b08063605093a4b3dc9f8f1"),
|
||||
b256!("011ac212f13c5dff2b2c6b600a79635103d6f580a4221079951181b25c7e6549"),
|
||||
])
|
||||
][..]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -696,6 +696,7 @@ impl TryFrom<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecove
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_primitives::{address, hex};
|
||||
use assert_matches::assert_matches;
|
||||
use bytes::Bytes;
|
||||
|
||||
@ -75,7 +75,7 @@ pub fn transaction_to_call_request(tx: TransactionSignedEcRecovered) -> Transact
|
||||
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();
|
||||
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
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
//! `Eth` bundle implementation and helpers.
|
||||
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_primitives::{Keccak256, U256};
|
||||
use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult};
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
|
||||
use reth_primitives::PooledTransactionsElement;
|
||||
use reth_primitives::{PooledTransactionsElement, Transaction};
|
||||
use reth_provider::{ChainSpecProvider, HeaderProvider};
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_rpc_eth_api::{
|
||||
@ -19,7 +20,7 @@ use revm::{
|
||||
primitives::{ResultAndState, TxEnv},
|
||||
};
|
||||
use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, SpecId, MAX_BLOB_GAS_PER_BLOCK};
|
||||
use std::sync::Arc;
|
||||
use std::{ops::Deref, sync::Arc};
|
||||
|
||||
/// `Eth` bundle implementation.
|
||||
pub struct EthBundle<Eth> {
|
||||
@ -179,8 +180,7 @@ where
|
||||
let tx = tx.into_transaction();
|
||||
|
||||
hasher.update(tx.hash());
|
||||
let gas_price = tx
|
||||
.effective_tip_per_gas(basefee)
|
||||
let gas_price = Transaction::effective_tip_per_gas(tx.deref(), basefee)
|
||||
.ok_or_else(|| RpcInvalidTransactionError::FeeCapTooLow)
|
||||
.map_err(Eth::Error::from_eth_err)?;
|
||||
eth_api.evm_config().fill_tx_env(evm.tx_mut(), &tx, signer);
|
||||
|
||||
@ -109,6 +109,7 @@ impl EthSigner for DevSigner {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloy_consensus::Transaction;
|
||||
use alloy_primitives::{Bytes, U256};
|
||||
use alloy_rpc_types_eth::TransactionInput;
|
||||
use revm_primitives::TxKind;
|
||||
|
||||
@ -11,6 +11,7 @@ reth-node-ethereum.workspace = true
|
||||
|
||||
alloy-rpc-types-beacon.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
|
||||
clap.workspace = true
|
||||
eyre.workspace = true
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use crate::BeaconSidecarConfig;
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_primitives::B256;
|
||||
use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, SidecarIterator};
|
||||
use eyre::Result;
|
||||
|
||||
Reference in New Issue
Block a user