Skip to content

Commit 810d04a

Browse files
committed
feat: add rlp for txtype
1 parent 2ab90d3 commit 810d04a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

crates/consensus/src/transaction/envelope.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ impl PartialEq<u8> for TxType {
6161
}
6262
}
6363

64+
impl PartialEq<TxType> for u8 {
65+
fn eq(&self, other: &TxType) -> bool {
66+
*self == *other as Self
67+
}
68+
}
69+
6470
#[cfg(any(test, feature = "arbitrary"))]
6571
impl arbitrary::Arbitrary<'_> for TxType {
6672
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
@@ -83,6 +89,23 @@ impl TryFrom<u8> for TxType {
8389
}
8490
}
8591

92+
impl Encodable for TxType {
93+
fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
94+
(*self as u8).encode(out);
95+
}
96+
97+
fn length(&self) -> usize {
98+
1
99+
}
100+
}
101+
102+
impl Decodable for TxType {
103+
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
104+
let ty = u8::decode(buf)?;
105+
Self::try_from(ty).map_err(|_| alloy_rlp::Error::Custom("invalid transaction type"))
106+
}
107+
}
108+
86109
/// The Ethereum [EIP-2718] Transaction Envelope.
87110
///
88111
/// # Note:

0 commit comments

Comments
 (0)