Skip to content

Commit 237583f

Browse files
authored
chore: use derive_more::FromStr (#6476)
1 parent 0ff6c7b commit 237583f

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

src/rpc/methods/eth.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,6 @@ impl EthHash {
283283
}
284284
}
285285

286-
impl FromStr for EthHash {
287-
type Err = anyhow::Error;
288-
289-
fn from_str(s: &str) -> Result<Self, Self::Err> {
290-
Ok(EthHash(ethereum_types::H256::from_str(s)?))
291-
}
292-
}
293-
294286
impl From<Cid> for EthHash {
295287
fn from(cid: Cid) -> Self {
296288
let (_, digest, _) = cid.hash().into_inner();
@@ -3722,7 +3714,7 @@ impl RpcMethod<1> for EthTraceTransaction {
37223714
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
37233715
(tx_hash,): Self::Params,
37243716
) -> Result<Self::Ok, ServerError> {
3725-
let eth_hash = EthHash::from_str(&tx_hash)?;
3717+
let eth_hash = EthHash::from_str(&tx_hash).context("invalid transaction hash")?;
37263718
let eth_txn = get_eth_transaction_by_hash(&ctx, &eth_hash, None)
37273719
.await?
37283720
.ok_or(ServerError::internal_error("transaction not found", None))?;

src/rpc/methods/eth/types.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl GetStorageAtParams {
111111
JsonSchema,
112112
derive_more::From,
113113
derive_more::Into,
114+
derive_more::FromStr,
114115
)]
115116
pub struct EthAddress(
116117
#[schemars(with = "String")]
@@ -211,16 +212,6 @@ impl EthAddress {
211212
}
212213
}
213214

214-
impl FromStr for EthAddress {
215-
type Err = anyhow::Error;
216-
217-
fn from_str(s: &str) -> Result<Self, Self::Err> {
218-
Ok(EthAddress(
219-
ethereum_types::Address::from_str(s).map_err(|e| anyhow::anyhow!("{e}"))?,
220-
))
221-
}
222-
}
223-
224215
impl TryFrom<&[u8]> for EthAddress {
225216
type Error = anyhow::Error;
226217

@@ -398,6 +389,7 @@ impl TryFrom<EthCallMessage> for Message {
398389
displaydoc::Display,
399390
derive_more::From,
400391
derive_more::Into,
392+
derive_more::FromStr,
401393
)]
402394
#[displaydoc("{0:#x}")]
403395
pub struct EthHash(#[schemars(with = "String")] pub ethereum_types::H256);

0 commit comments

Comments
 (0)