-
Notifications
You must be signed in to change notification settings - Fork 253
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: support no_std for alloy-eips
#181
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,48 @@ | |
//! | ||
//! [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 | ||
|
||
#[cfg(not(feature = "std"))] | ||
use crate::alloc::{vec, vec::Vec}; | ||
|
||
use alloy_primitives::{keccak256, Sealed, B256}; | ||
use alloy_rlp::{BufMut, Header, EMPTY_STRING_CODE}; | ||
use core::{ | ||
fmt, | ||
fmt::{Display, Formatter}, | ||
}; | ||
|
||
// https://eips.ethereum.org/EIPS/eip-2718#transactiontype-only-goes-up-to-0x7f | ||
const TX_TYPE_BYTE_MAX: u8 = 0x7f; | ||
|
||
/// [EIP-2718] decoding errors. | ||
/// | ||
/// [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718 | ||
#[derive(thiserror::Error, Debug)] | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum Eip2718Error { | ||
/// Rlp error from [`alloy_rlp`]. | ||
#[error(transparent)] | ||
RlpError(#[from] alloy_rlp::Error), | ||
RlpError(alloy_rlp::Error), | ||
/// Got an unexpected type flag while decoding. | ||
#[error("Unexpected type flag. Got {0}.")] | ||
UnexpectedType(u8), | ||
/// Some other error occurred. | ||
#[error(transparent)] | ||
Custom(#[from] Box<dyn std::error::Error>), | ||
Comment on lines
-22
to
-24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think eventually we'd need this, so perhaps the better question for this PR is, does this type even belong in here? perhaps we should rather move this to the consensus crate instead, I believe it's better suited in there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that might be a break change, which the current one is not? Maybe it should be improved in subsequent versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing a variant is a breaking change as well, I'd really prefer moving the error. imo it does not belong in the eip crate |
||
} | ||
|
||
impl Display for Eip2718Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::RlpError(err) => write!(f, "{err}"), | ||
Self::UnexpectedType(t) => write!(f, "Unexpected type flag. Got {t}."), | ||
} | ||
} | ||
} | ||
|
||
impl From<alloy_rlp::Error> for Eip2718Error { | ||
fn from(err: alloy_rlp::Error) -> Self { | ||
Self::RlpError(err) | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for Eip2718Error {} | ||
|
||
/// Decoding trait for [EIP-2718] envelopes. These envelopes wrap a transaction | ||
/// or a receipt with a type flag. | ||
/// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should move this error type and keep the custom variant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i want to how tohandle the related trait