mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Introduce trait for OpTransaction (#11745)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -8260,6 +8260,7 @@ dependencies = [
|
||||
"alloy-primitives",
|
||||
"alloy-rlp",
|
||||
"alloy-rpc-types-engine",
|
||||
"op-alloy-consensus",
|
||||
"op-alloy-rpc-types-engine",
|
||||
"reth-basic-payload-builder",
|
||||
"reth-chain-state",
|
||||
|
||||
@ -5,6 +5,7 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_eips::eip7685::Requests;
|
||||
use core::fmt::Display;
|
||||
use op_alloy_consensus::DepositTransaction;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_consensus::ConsensusError;
|
||||
use reth_evm::{
|
||||
|
||||
@ -39,6 +39,7 @@ alloy-eips.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
op-alloy-rpc-types-engine.workspace = true
|
||||
op-alloy-consensus.workspace = true
|
||||
alloy-rpc-types-engine.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
|
||||
@ -54,5 +55,5 @@ optimism = [
|
||||
"reth-optimism-evm/optimism",
|
||||
"revm/optimism",
|
||||
"reth-execution-types/optimism",
|
||||
"reth-optimism-consensus/optimism",
|
||||
"reth-optimism-consensus/optimism"
|
||||
]
|
||||
@ -36,6 +36,7 @@ use crate::{
|
||||
error::OptimismPayloadBuilderError,
|
||||
payload::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes},
|
||||
};
|
||||
use op_alloy_consensus::DepositTransaction;
|
||||
|
||||
/// Optimism's payload builder
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
|
||||
use alloy_eips::eip2718::Encodable2718;
|
||||
use alloy_rpc_types::{AnyReceiptEnvelope, Log, TransactionReceipt};
|
||||
use op_alloy_consensus::{OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope};
|
||||
use op_alloy_consensus::{
|
||||
DepositTransaction, OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope,
|
||||
};
|
||||
use op_alloy_rpc_types::{receipt::L1BlockInfo, OpTransactionReceipt, OpTransactionReceiptFields};
|
||||
use reth_node_api::{FullNodeComponents, NodeTypes};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
use alloy_consensus::Transaction as _;
|
||||
use alloy_primitives::{Bytes, B256};
|
||||
use alloy_rpc_types::TransactionInfo;
|
||||
use op_alloy_consensus::DepositTransaction;
|
||||
use op_alloy_rpc_types::Transaction;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_primitives::TransactionSignedEcRecovered;
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
use crate::{Transaction, TransactionSigned};
|
||||
use alloy_primitives::{Address, TxKind, U256};
|
||||
#[cfg(feature = "optimism")]
|
||||
use op_alloy_consensus::DepositTransaction;
|
||||
use revm_primitives::{AuthorizationList, TxEnv};
|
||||
|
||||
/// Implements behaviour to fill a [`TxEnv`] from another transaction.
|
||||
|
||||
@ -18,6 +18,8 @@ use derive_more::{AsRef, Deref};
|
||||
use once_cell as _;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use once_cell::sync::Lazy as LazyLock;
|
||||
#[cfg(feature = "optimism")]
|
||||
use op_alloy_consensus::DepositTransaction;
|
||||
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use signature::{decode_with_eip155_chain_id, with_eip155_parity};
|
||||
@ -136,6 +138,31 @@ pub enum Transaction {
|
||||
Deposit(TxDeposit),
|
||||
}
|
||||
|
||||
#[cfg(feature = "optimism")]
|
||||
impl DepositTransaction for Transaction {
|
||||
fn source_hash(&self) -> Option<B256> {
|
||||
match self {
|
||||
Self::Deposit(tx) => tx.source_hash(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn mint(&self) -> Option<u128> {
|
||||
match self {
|
||||
Self::Deposit(tx) => tx.mint(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn is_system_transaction(&self) -> bool {
|
||||
match self {
|
||||
Self::Deposit(tx) => tx.is_system_transaction(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn is_deposit(&self) -> bool {
|
||||
matches!(self, Self::Deposit(_))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "arbitrary"))]
|
||||
impl<'a> arbitrary::Arbitrary<'a> for Transaction {
|
||||
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
@ -361,42 +388,6 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the source hash of the transaction, which uniquely identifies its source.
|
||||
/// If not a deposit transaction, this will always return `None`.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn source_hash(&self) -> Option<B256> {
|
||||
match self {
|
||||
Self::Deposit(TxDeposit { source_hash, .. }) => Some(*source_hash),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the amount of ETH locked up on L1 that will be minted on L2. If the transaction
|
||||
/// is not a deposit transaction, this will always return `None`.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn mint(&self) -> Option<u128> {
|
||||
match self {
|
||||
Self::Deposit(TxDeposit { mint, .. }) => *mint,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether or not the transaction is a system transaction. If the transaction
|
||||
/// is not a deposit transaction, this will always return `false`.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn is_system_transaction(&self) -> bool {
|
||||
match self {
|
||||
Self::Deposit(TxDeposit { is_system_transaction, .. }) => *is_system_transaction,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether or not the transaction is an Optimism Deposited transaction.
|
||||
#[cfg(feature = "optimism")]
|
||||
pub const fn is_deposit(&self) -> bool {
|
||||
matches!(self, Self::Deposit(_))
|
||||
}
|
||||
|
||||
/// This encodes the transaction _without_ the signature, and is only suitable for creating a
|
||||
/// hash intended for signing.
|
||||
pub fn encode_without_signature(&self, out: &mut dyn bytes::BufMut) {
|
||||
|
||||
Reference in New Issue
Block a user