Skip to content

Commit

Permalink
Merge branch 'main' into emhane/tx-receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Sep 29, 2024
2 parents 13febdb + 599e577 commit 831becd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ arbitrary = { workspace = true, features = ["derive"], optional = true }
# serde
serde = { workspace = true, features = ["derive"], optional = true }

# misc
derive_more = { workspace = true, features = [
"from",
"deref",
"deref_mut",
"into_iterator"
], default-features = false }
auto_impl.workspace = true

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["arbitrary", "rand"] }
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/src/receipt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use status::Eip658Value;

/// Receipt is the result of a transaction execution.
#[doc(alias = "TransactionReceipt")]
#[auto_impl::auto_impl(&, Arc)]
pub trait TxReceipt<T = Log> {
/// Returns the status or post state of the transaction.
///
Expand Down
22 changes: 21 additions & 1 deletion crates/eips/src/eip1898.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ impl Display for BlockId {
pub enum ParseBlockIdError {
/// Failed to parse a block id from a number.
ParseIntError(ParseIntError),
/// Failed to parse hex number
ParseError(ParseError),
/// Failed to parse a block id as a hex string.
FromHexError(FromHexError),
}
Expand All @@ -552,6 +554,7 @@ impl Display for ParseBlockIdError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::ParseIntError(err) => write!(f, "{err}"),
Self::ParseError(err) => write!(f, "{err}"),
Self::FromHexError(err) => write!(f, "{err}"),
}
}
Expand All @@ -563,6 +566,7 @@ impl std::error::Error for ParseBlockIdError {
match self {
Self::ParseIntError(err) => std::error::Error::source(err),
Self::FromHexError(err) => std::error::Error::source(err),
Self::ParseError(err) => std::error::Error::source(err),
}
}
}
Expand All @@ -583,7 +587,11 @@ impl FromStr for BlockId {
type Err = ParseBlockIdError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.starts_with("0x") {
return B256::from_str(s).map(Into::into).map_err(ParseBlockIdError::FromHexError);
return if s.len() == 66 {
B256::from_str(s).map(Into::into).map_err(ParseBlockIdError::FromHexError)
} else {
U64::from_str(s).map(Into::into).map_err(ParseBlockIdError::ParseError)
};
}

match s {
Expand Down Expand Up @@ -796,6 +804,18 @@ mod tests {

const HASH: B256 = b256!("1a15e3c30cf094a99826869517b16d185d45831d3a494f01030b0001a9d3ebb9");

#[test]
fn block_id_from_str() {
assert_eq!("0x0".parse::<BlockId>().unwrap(), BlockId::number(0));
assert_eq!("0x24A931".parse::<BlockId>().unwrap(), BlockId::number(2402609));
assert_eq!(
"0x1a15e3c30cf094a99826869517b16d185d45831d3a494f01030b0001a9d3ebb9"
.parse::<BlockId>()
.unwrap(),
HASH.into()
);
}

#[test]
#[cfg(feature = "serde")]
fn compact_block_number_serde() {
Expand Down

0 comments on commit 831becd

Please sign in to comment.