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

feat: impl Transaction for TxEnvelope #1006

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
69 changes: 67 additions & 2 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::fmt;

use crate::{Signed, TxEip1559, TxEip2930, TxLegacy};
use crate::{Signed, Transaction, TxEip1559, TxEip2930, TxLegacy};
use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718};
use alloy_primitives::B256;
use alloy_primitives::{TxKind, B256};
use alloy_rlp::{Decodable, Encodable, Header};

use crate::transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar};
Expand Down Expand Up @@ -361,6 +361,71 @@ impl Encodable2718 for TxEnvelope {
}
}

impl Transaction for TxEnvelope {
fn chain_id(&self) -> Option<alloy_primitives::ChainId> {
match self {
Self::Legacy(tx) => tx.tx().chain_id(),
Self::Eip2930(tx) => tx.tx().chain_id(),
Self::Eip1559(tx) => tx.tx().chain_id(),
Self::Eip4844(tx) => tx.tx().chain_id(),
}
}

fn gas_limit(&self) -> u128 {
match self {
Self::Legacy(tx) => tx.tx().gas_limit(),
Self::Eip2930(tx) => tx.tx().gas_limit(),
Self::Eip1559(tx) => tx.tx().gas_limit(),
Self::Eip4844(tx) => tx.tx().gas_limit(),
}
}

fn gas_price(&self) -> Option<u128> {
match self {
Self::Legacy(tx) => tx.tx().gas_price(),
Self::Eip2930(tx) => tx.tx().gas_price(),
Self::Eip1559(tx) => tx.tx().gas_price(),
Self::Eip4844(tx) => tx.tx().gas_price(),
}
}

fn input(&self) -> &[u8] {
match self {
Self::Legacy(tx) => tx.tx().input(),
Self::Eip2930(tx) => tx.tx().input(),
Self::Eip1559(tx) => tx.tx().input(),
Self::Eip4844(tx) => tx.tx().input(),
}
}

fn nonce(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.tx().nonce(),
Self::Eip2930(tx) => tx.tx().nonce(),
Self::Eip1559(tx) => tx.tx().nonce(),
Self::Eip4844(tx) => tx.tx().nonce(),
}
}

fn to(&self) -> TxKind {
match self {
Self::Legacy(tx) => tx.tx().to(),
Self::Eip2930(tx) => tx.tx().to(),
Self::Eip1559(tx) => tx.tx().to(),
Self::Eip4844(tx) => tx.tx().to(),
}
}

fn value(&self) -> alloy_primitives::U256 {
match self {
Self::Legacy(tx) => tx.tx().value(),
Self::Eip2930(tx) => tx.tx().value(),
Self::Eip1559(tx) => tx.tx().value(),
Self::Eip4844(tx) => tx.tx().value(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down