From b411b255f231999dbf807f500618506178542975 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Fri, 23 Jan 2026 18:44:48 +0100 Subject: [PATCH] chore: use `derive_more::FromStr` --- src/rpc/methods/eth.rs | 10 +--------- src/rpc/methods/eth/types.rs | 12 ++---------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 507cbdbdaa30..5028bb497954 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -283,14 +283,6 @@ impl EthHash { } } -impl FromStr for EthHash { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - Ok(EthHash(ethereum_types::H256::from_str(s)?)) - } -} - impl From for EthHash { fn from(cid: Cid) -> Self { let (_, digest, _) = cid.hash().into_inner(); @@ -3722,7 +3714,7 @@ impl RpcMethod<1> for EthTraceTransaction { ctx: Ctx, (tx_hash,): Self::Params, ) -> Result { - let eth_hash = EthHash::from_str(&tx_hash)?; + let eth_hash = EthHash::from_str(&tx_hash).context("invalid transaction hash")?; let eth_txn = get_eth_transaction_by_hash(&ctx, ð_hash, None) .await? .ok_or(ServerError::internal_error("transaction not found", None))?; diff --git a/src/rpc/methods/eth/types.rs b/src/rpc/methods/eth/types.rs index 89ef1d88edf2..336bb48a50b3 100644 --- a/src/rpc/methods/eth/types.rs +++ b/src/rpc/methods/eth/types.rs @@ -111,6 +111,7 @@ impl GetStorageAtParams { JsonSchema, derive_more::From, derive_more::Into, + derive_more::FromStr, )] pub struct EthAddress( #[schemars(with = "String")] @@ -211,16 +212,6 @@ impl EthAddress { } } -impl FromStr for EthAddress { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - Ok(EthAddress( - ethereum_types::Address::from_str(s).map_err(|e| anyhow::anyhow!("{e}"))?, - )) - } -} - impl TryFrom<&[u8]> for EthAddress { type Error = anyhow::Error; @@ -398,6 +389,7 @@ impl TryFrom for Message { displaydoc::Display, derive_more::From, derive_more::Into, + derive_more::FromStr, )] #[displaydoc("{0:#x}")] pub struct EthHash(#[schemars(with = "String")] pub ethereum_types::H256);