diff --git a/crates/consensus/Cargo.toml b/crates/consensus/Cargo.toml index 18d3729f33d..57804eba49c 100644 --- a/crates/consensus/Cargo.toml +++ b/crates/consensus/Cargo.toml @@ -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"] } diff --git a/crates/consensus/src/receipt/mod.rs b/crates/consensus/src/receipt/mod.rs index 6b91ddd614a..eae5bd27bba 100644 --- a/crates/consensus/src/receipt/mod.rs +++ b/crates/consensus/src/receipt/mod.rs @@ -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 { /// Returns the status or post state of the transaction. /// diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 56be68bff2d..3780560f519 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -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), } @@ -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}"), } } @@ -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), } } } @@ -583,7 +587,11 @@ impl FromStr for BlockId { type Err = ParseBlockIdError; fn from_str(s: &str) -> Result { 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 { @@ -796,6 +804,18 @@ mod tests { const HASH: B256 = b256!("1a15e3c30cf094a99826869517b16d185d45831d3a494f01030b0001a9d3ebb9"); + #[test] + fn block_id_from_str() { + assert_eq!("0x0".parse::().unwrap(), BlockId::number(0)); + assert_eq!("0x24A931".parse::().unwrap(), BlockId::number(2402609)); + assert_eq!( + "0x1a15e3c30cf094a99826869517b16d185d45831d3a494f01030b0001a9d3ebb9" + .parse::() + .unwrap(), + HASH.into() + ); + } + #[test] #[cfg(feature = "serde")] fn compact_block_number_serde() {