Skip to content

Commit

Permalink
feat(alloy-consensus): EIP4844 tx support (alloy-rs#185)
Browse files Browse the repository at this point in the history
* feat(consensus): eip4844 scaffold

* chore: use alloy_eips for constants

* chore: tests, add arbitrary extensions for 4844
  • Loading branch information
Evalir authored Feb 5, 2024
1 parent 6d457a5 commit 5d51ee9
Show file tree
Hide file tree
Showing 5 changed files with 414 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ mod receipt;
pub use receipt::{Receipt, ReceiptEnvelope, ReceiptWithBloom};

mod transaction;
pub use transaction::{TxEip1559, TxEip2930, TxEnvelope, TxLegacy, TxType};
pub use transaction::{TxEip1559, TxEip2930, TxEip4844, TxEnvelope, TxLegacy, TxType};

pub use alloy_network::TxKind;
23 changes: 17 additions & 6 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub enum ReceiptEnvelope {
///
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
Eip1559(ReceiptWithBloom),
/// Receipt envelope with type flag 2, containing a [EIP-4844] receipt.
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
Eip4844(ReceiptWithBloom),
}

impl ReceiptEnvelope {
Expand All @@ -35,26 +39,31 @@ impl ReceiptEnvelope {
Self::Legacy(_) | Self::TaggedLegacy(_) => TxType::Legacy,
Self::Eip2930(_) => TxType::Eip2930,
Self::Eip1559(_) => TxType::Eip1559,
Self::Eip4844(_) => TxType::Eip4844,
}
}

/// Return the inner receipt with bloom. Currently this is infallible,
/// however, future receipt types may be added.
pub const fn as_receipt_with_bloom(&self) -> Option<&ReceiptWithBloom> {
match self {
Self::Legacy(t) | Self::TaggedLegacy(t) | Self::Eip2930(t) | Self::Eip1559(t) => {
Some(t)
}
Self::Legacy(t)
| Self::TaggedLegacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t) => Some(t),
}
}

/// Return the inner receipt. Currently this is infallible, however, future
/// receipt types may be added.
pub const fn as_receipt(&self) -> Option<&Receipt> {
match self {
Self::Legacy(t) | Self::TaggedLegacy(t) | Self::Eip2930(t) | Self::Eip1559(t) => {
Some(&t.receipt)
}
Self::Legacy(t)
| Self::TaggedLegacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t) => Some(&t.receipt),
}
}

Expand Down Expand Up @@ -104,6 +113,7 @@ impl Encodable2718 for ReceiptEnvelope {
Self::TaggedLegacy(_) => Some(TxType::Legacy as u8),
Self::Eip2930(_) => Some(TxType::Eip2930 as u8),
Self::Eip1559(_) => Some(TxType::Eip1559 as u8),
Self::Eip4844(_) => Some(TxType::Eip4844 as u8),
}
}

Expand All @@ -127,6 +137,7 @@ impl Decodable2718 for ReceiptEnvelope {
TxType::Legacy => Ok(Self::TaggedLegacy(receipt)),
TxType::Eip2930 => Ok(Self::Eip2930(receipt)),
TxType::Eip1559 => Ok(Self::Eip1559(receipt)),
TxType::Eip4844 => Ok(Self::Eip4844(receipt)),
}
}

Expand Down
Loading

0 comments on commit 5d51ee9

Please sign in to comment.