Skip to content

Commit

Permalink
feat: impl From<Eip2718Error> for alloy_rlp::Error (alloy-rs#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored and lwedge99 committed Oct 8, 2024
1 parent 22f76fe commit 1bb693e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 1 addition & 8 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,7 @@ impl Encodable for TxEnvelope {

impl Decodable for TxEnvelope {
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
match Self::network_decode(buf) {
Ok(t) => Ok(t),
Err(Eip2718Error::RlpError(e)) => Err(e),
Err(Eip2718Error::UnexpectedType(_)) => {
Err(alloy_rlp::Error::Custom("unexpected tx type"))
}
_ => Err(alloy_rlp::Error::Custom("unknown error decoding tx envelope")),
}
Ok(Self::network_decode(buf)?)
}
}

Expand Down
9 changes: 9 additions & 0 deletions crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ impl From<alloy_rlp::Error> for Eip2718Error {
}
}

impl From<Eip2718Error> for alloy_rlp::Error {
fn from(err: Eip2718Error) -> Self {
match err {
Eip2718Error::RlpError(err) => err,
Eip2718Error::UnexpectedType(_) => alloy_rlp::Error::Custom("Unexpected type flag"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for Eip2718Error {}

Expand Down

0 comments on commit 1bb693e

Please sign in to comment.