From 647945718fb6fbd85924899008077484edbc5128 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:20:35 +0200 Subject: [PATCH] Use `into()` to get `BlockHashOrNumber` (#997) Use into() to get BlockHashOrNumber --- src/eth_provider/provider.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index 09d69a5d8..e574172fe 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -153,9 +153,7 @@ where async fn header(&self, block_id: &BlockId) -> EthProviderResult> { let block = match block_id { BlockId::Hash(hash) => BlockHashOrNumber::Hash((*hash).into()), - BlockId::Number(number_or_tag) => { - BlockHashOrNumber::Number(self.tag_into_block_number(*number_or_tag).await?.to()) - } + BlockId::Number(number_or_tag) => self.tag_into_block_number(*number_or_tag).await?.to::().into(), }; Ok(self.header(block).await?.map(|h| h.header)) @@ -197,7 +195,7 @@ where } async fn block_by_hash(&self, hash: B256, full: bool) -> EthProviderResult> { - Ok(self.block(BlockHashOrNumber::Hash(hash), full).await?) + Ok(self.block(hash.into(), full).await?) } async fn block_by_number( @@ -206,11 +204,11 @@ where full: bool, ) -> EthProviderResult> { let block_number = self.tag_into_block_number(number_or_tag).await?; - Ok(self.block(BlockHashOrNumber::Number(block_number.to::()), full).await?) + Ok(self.block(block_number.to::().into(), full).await?) } async fn block_transaction_count_by_hash(&self, hash: B256) -> EthProviderResult> { - Ok(if self.block_exists(BlockHashOrNumber::Hash(hash)).await? { + Ok(if self.block_exists(hash.into()).await? { Some(U256::from( self.database.count::(into_filter("tx.blockHash", &hash, HASH_PADDING)).await?, )) @@ -224,7 +222,7 @@ where number_or_tag: BlockNumberOrTag, ) -> EthProviderResult> { let block_number = self.tag_into_block_number(number_or_tag).await?; - let block_exists = self.block_exists(BlockHashOrNumber::Number(block_number.to::())).await?; + let block_exists = self.block_exists(block_number.to::().into()).await?; if !block_exists { return Ok(None); } @@ -591,7 +589,7 @@ where match block_id { BlockId::Number(maybe_number) => { let block_number = self.tag_into_block_number(maybe_number).await?; - let block_exists = self.block_exists(BlockHashOrNumber::Number(block_number.to())).await?; + let block_exists = self.block_exists(block_number.to::().into()).await?; if !block_exists { return Ok(None); } @@ -601,7 +599,7 @@ where Ok(Some(tx.into_iter().map(Into::into).collect())) } BlockId::Hash(hash) => { - let block_exists = self.block_exists(BlockHashOrNumber::Hash(hash.block_hash)).await?; + let block_exists = self.block_exists(hash.block_hash.into()).await?; if !block_exists { return Ok(None); } @@ -618,10 +616,8 @@ where block_id: Option, ) -> EthProviderResult>> { let block_id = match block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)) { - BlockId::Number(maybe_number) => { - BlockHashOrNumber::Number(self.tag_into_block_number(maybe_number).await?.to()) - } - BlockId::Hash(hash) => BlockHashOrNumber::Hash(hash.block_hash), + BlockId::Number(maybe_number) => self.tag_into_block_number(maybe_number).await?.to::().into(), + BlockId::Hash(hash) => hash.block_hash.into(), }; if !self.block_exists(block_id).await? { return Ok(None); @@ -867,10 +863,7 @@ where // 3. The block number is not found, then we return an error match number_or_tag { BlockNumberOrTag::Number(number) => { - let header = self - .header(BlockHashOrNumber::Number(number)) - .await? - .ok_or(EthApiError::UnknownBlockNumber)?; + let header = self.header(number.into()).await?.ok_or(EthApiError::UnknownBlockNumber)?; // If the block hash is zero, then the block corresponds to a Starknet pending block if header.header.hash.ok_or(EthApiError::UnknownBlock)?.is_zero() { Ok(starknet::core::types::BlockId::Tag(starknet::core::types::BlockTag::Pending))