op_alloy_consensus/transaction/
typed.rsuse crate::{OpTxEnvelope, OpTxType, TxDeposit};
use alloy_consensus::{Transaction, TxEip1559, TxEip2930, TxEip4844Variant, TxLegacy};
use alloy_eips::eip2930::AccessList;
use alloy_primitives::TxKind;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
pub enum OpTypedTransaction {
#[cfg_attr(feature = "serde", serde(rename = "0x00", alias = "0x0"))]
Legacy(TxLegacy),
#[cfg_attr(feature = "serde", serde(rename = "0x01", alias = "0x1"))]
Eip2930(TxEip2930),
#[cfg_attr(feature = "serde", serde(rename = "0x02", alias = "0x2"))]
Eip1559(TxEip1559),
#[cfg_attr(feature = "serde", serde(rename = "0x03", alias = "0x3"))]
Eip4844(TxEip4844Variant),
#[cfg_attr(feature = "serde", serde(rename = "0x7E", alias = "0x7E"))]
Deposit(TxDeposit),
}
impl From<TxLegacy> for OpTypedTransaction {
fn from(tx: TxLegacy) -> Self {
Self::Legacy(tx)
}
}
impl From<TxEip2930> for OpTypedTransaction {
fn from(tx: TxEip2930) -> Self {
Self::Eip2930(tx)
}
}
impl From<TxEip1559> for OpTypedTransaction {
fn from(tx: TxEip1559) -> Self {
Self::Eip1559(tx)
}
}
impl From<TxEip4844Variant> for OpTypedTransaction {
fn from(tx: TxEip4844Variant) -> Self {
Self::Eip4844(tx)
}
}
impl From<TxDeposit> for OpTypedTransaction {
fn from(tx: TxDeposit) -> Self {
Self::Deposit(tx)
}
}
impl From<OpTxEnvelope> for OpTypedTransaction {
fn from(envelope: OpTxEnvelope) -> Self {
match envelope {
OpTxEnvelope::Legacy(tx) => Self::Legacy(tx.strip_signature()),
OpTxEnvelope::Eip2930(tx) => Self::Eip2930(tx.strip_signature()),
OpTxEnvelope::Eip1559(tx) => Self::Eip1559(tx.strip_signature()),
OpTxEnvelope::Eip4844(tx) => Self::Eip4844(tx.strip_signature()),
OpTxEnvelope::Deposit(tx) => Self::Deposit(tx),
}
}
}
impl OpTypedTransaction {
pub const fn tx_type(&self) -> OpTxType {
match self {
Self::Legacy(_) => OpTxType::Legacy,
Self::Eip2930(_) => OpTxType::Eip2930,
Self::Eip1559(_) => OpTxType::Eip1559,
Self::Eip4844(_) => OpTxType::Eip4844,
Self::Deposit(_) => OpTxType::Deposit,
}
}
pub const fn legacy(&self) -> Option<&TxLegacy> {
match self {
Self::Legacy(tx) => Some(tx),
_ => None,
}
}
pub const fn eip2930(&self) -> Option<&TxEip2930> {
match self {
Self::Eip2930(tx) => Some(tx),
_ => None,
}
}
pub const fn eip1559(&self) -> Option<&TxEip1559> {
match self {
Self::Eip1559(tx) => Some(tx),
_ => None,
}
}
pub const fn eip4844(&self) -> Option<&TxEip4844Variant> {
match self {
Self::Eip4844(tx) => Some(tx),
_ => None,
}
}
pub const fn deposit(&self) -> Option<&TxDeposit> {
match self {
Self::Deposit(tx) => Some(tx),
_ => None,
}
}
}
impl Transaction for OpTypedTransaction {
fn chain_id(&self) -> Option<alloy_primitives::ChainId> {
match self {
Self::Legacy(tx) => tx.chain_id(),
Self::Eip2930(tx) => tx.chain_id(),
Self::Eip1559(tx) => tx.chain_id(),
Self::Eip4844(tx) => tx.chain_id(),
Self::Deposit(tx) => tx.chain_id(),
}
}
fn nonce(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.nonce(),
Self::Eip2930(tx) => tx.nonce(),
Self::Eip1559(tx) => tx.nonce(),
Self::Eip4844(tx) => tx.nonce(),
Self::Deposit(tx) => tx.nonce(),
}
}
fn gas_limit(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.gas_limit(),
Self::Eip2930(tx) => tx.gas_limit(),
Self::Eip1559(tx) => tx.gas_limit(),
Self::Eip4844(tx) => tx.gas_limit(),
Self::Deposit(tx) => tx.gas_limit(),
}
}
fn gas_price(&self) -> Option<u128> {
match self {
Self::Legacy(tx) => tx.gas_price(),
Self::Eip2930(tx) => tx.gas_price(),
Self::Eip1559(tx) => tx.gas_price(),
Self::Eip4844(tx) => tx.gas_price(),
Self::Deposit(tx) => tx.gas_price(),
}
}
fn max_fee_per_gas(&self) -> u128 {
match self {
Self::Legacy(tx) => tx.max_fee_per_gas(),
Self::Eip2930(tx) => tx.max_fee_per_gas(),
Self::Eip1559(tx) => tx.max_fee_per_gas(),
Self::Eip4844(tx) => tx.max_fee_per_gas(),
Self::Deposit(tx) => tx.max_fee_per_gas(),
}
}
fn max_priority_fee_per_gas(&self) -> Option<u128> {
match self {
Self::Legacy(tx) => tx.max_priority_fee_per_gas(),
Self::Eip2930(tx) => tx.max_priority_fee_per_gas(),
Self::Eip1559(tx) => tx.max_priority_fee_per_gas(),
Self::Eip4844(tx) => tx.max_priority_fee_per_gas(),
Self::Deposit(tx) => tx.max_priority_fee_per_gas(),
}
}
fn max_fee_per_blob_gas(&self) -> Option<u128> {
match self {
Self::Legacy(tx) => tx.max_fee_per_blob_gas(),
Self::Eip2930(tx) => tx.max_fee_per_blob_gas(),
Self::Eip1559(tx) => tx.max_fee_per_blob_gas(),
Self::Eip4844(tx) => tx.max_fee_per_blob_gas(),
Self::Deposit(tx) => tx.max_fee_per_blob_gas(),
}
}
fn priority_fee_or_price(&self) -> u128 {
match self {
Self::Legacy(tx) => tx.priority_fee_or_price(),
Self::Eip2930(tx) => tx.priority_fee_or_price(),
Self::Eip1559(tx) => tx.priority_fee_or_price(),
Self::Eip4844(tx) => tx.priority_fee_or_price(),
Self::Deposit(tx) => tx.priority_fee_or_price(),
}
}
fn to(&self) -> TxKind {
match self {
Self::Legacy(tx) => tx.to(),
Self::Eip2930(tx) => tx.to(),
Self::Eip1559(tx) => tx.to(),
Self::Eip4844(tx) => tx.to(),
Self::Deposit(tx) => tx.to(),
}
}
fn value(&self) -> alloy_primitives::U256 {
match self {
Self::Legacy(tx) => tx.value(),
Self::Eip2930(tx) => tx.value(),
Self::Eip1559(tx) => tx.value(),
Self::Eip4844(tx) => tx.value(),
Self::Deposit(tx) => tx.value(),
}
}
fn input(&self) -> &[u8] {
match self {
Self::Legacy(tx) => tx.input(),
Self::Eip2930(tx) => tx.input(),
Self::Eip1559(tx) => tx.input(),
Self::Eip4844(tx) => tx.input(),
Self::Deposit(tx) => tx.input(),
}
}
fn ty(&self) -> u8 {
match self {
Self::Legacy(_) => OpTxType::Legacy as u8,
Self::Eip2930(_) => OpTxType::Eip2930 as u8,
Self::Eip1559(_) => OpTxType::Eip1559 as u8,
Self::Eip4844(_) => OpTxType::Eip4844 as u8,
Self::Deposit(_) => OpTxType::Deposit as u8,
}
}
fn access_list(&self) -> Option<&AccessList> {
match self {
Self::Legacy(tx) => tx.access_list(),
Self::Eip2930(tx) => tx.access_list(),
Self::Eip1559(tx) => tx.access_list(),
Self::Eip4844(tx) => tx.access_list(),
Self::Deposit(tx) => tx.access_list(),
}
}
fn blob_versioned_hashes(&self) -> Option<&[alloy_primitives::B256]> {
match self {
Self::Legacy(tx) => tx.blob_versioned_hashes(),
Self::Eip2930(tx) => tx.blob_versioned_hashes(),
Self::Eip1559(tx) => tx.blob_versioned_hashes(),
Self::Eip4844(tx) => tx.blob_versioned_hashes(),
Self::Deposit(tx) => tx.blob_versioned_hashes(),
}
}
fn authorization_list(&self) -> Option<&[alloy_eips::eip7702::SignedAuthorization]> {
match self {
Self::Legacy(tx) => tx.authorization_list(),
Self::Eip2930(tx) => tx.authorization_list(),
Self::Eip1559(tx) => tx.authorization_list(),
Self::Eip4844(tx) => tx.authorization_list(),
Self::Deposit(tx) => tx.authorization_list(),
}
}
}