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: add rlp for txtype #1648

Merged
merged 1 commit into from
Nov 14, 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
23 changes: 23 additions & 0 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl PartialEq<u8> for TxType {
}
}

impl PartialEq<TxType> for u8 {
fn eq(&self, other: &TxType) -> bool {
*self == *other as Self
}
}

#[cfg(any(test, feature = "arbitrary"))]
impl arbitrary::Arbitrary<'_> for TxType {
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
Expand All @@ -83,6 +89,23 @@ impl TryFrom<u8> for TxType {
}
}

impl Encodable for TxType {
fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
(*self as u8).encode(out);
}

fn length(&self) -> usize {
1
}
}

impl Decodable for TxType {
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
let ty = u8::decode(buf)?;
Self::try_from(ty).map_err(|_| alloy_rlp::Error::Custom("invalid transaction type"))
}
}

/// The Ethereum [EIP-2718] Transaction Envelope.
///
/// # Note:
Expand Down