From 4c0762e05c1e45d88bef6213f3198738bc4f1d20 Mon Sep 17 00:00:00 2001 From: PJColombo Date: Wed, 19 Jun 2024 13:34:36 +0200 Subject: [PATCH] style: resolve clippy issues --- src/clients/beacon/types.rs | 23 ----------------------- src/context.rs | 20 ++++++++++---------- src/indexer/event_handlers/head.rs | 2 -- src/slots_processor/mod.rs | 22 ++-------------------- 4 files changed, 12 insertions(+), 55 deletions(-) diff --git a/src/clients/beacon/types.rs b/src/clients/beacon/types.rs index 0ae29cb..e7036cf 100644 --- a/src/clients/beacon/types.rs +++ b/src/clients/beacon/types.rs @@ -3,8 +3,6 @@ use std::{fmt, str::FromStr}; use ethers::types::{Bytes, H256}; use serde::{Deserialize, Serialize}; -use crate::slots_processor::BlockData; - #[derive(Serialize, Debug, Clone, PartialEq)] pub enum BlockId { Head, @@ -18,7 +16,6 @@ pub enum BlockId { pub enum Topic { Head, FinalizedCheckpoint, - ChainReorg, } #[derive(Deserialize, Debug)] @@ -86,16 +83,6 @@ pub struct BlockHeaderMessage { pub slot: u32, } -#[derive(Deserialize, Debug)] -pub struct ChainReorgEventData { - pub old_head_block: H256, - pub new_head_block: H256, - #[serde(deserialize_with = "deserialize_number")] - pub slot: u32, - #[serde(deserialize_with = "deserialize_number")] - pub depth: u32, -} - #[derive(Deserialize, Debug)] pub struct HeadEventData { #[serde(deserialize_with = "deserialize_number")] @@ -168,18 +155,8 @@ impl FromStr for BlockId { impl From<&Topic> for String { fn from(value: &Topic) -> Self { match value { - Topic::ChainReorg => String::from("chain_reorg"), Topic::Head => String::from("head"), Topic::FinalizedCheckpoint => String::from("finalized_checkpoint"), } } } - -impl From for BlockData { - fn from(event_data: HeadEventData) -> Self { - Self { - root: event_data.block, - slot: event_data.slot, - } - } -} diff --git a/src/context.rs b/src/context.rs index ace4648..9cdedbd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -17,8 +17,8 @@ use crate::{ use crate::clients::{beacon::MockCommonBeaconClient, blobscan::MockCommonBlobscanClient}; pub trait CommonContext: Send + Sync + Debug + DynClone { - fn beacon_client(&self) -> &Box; - fn blobscan_client(&self) -> &Box; + fn beacon_client(&self) -> &dyn CommonBeaconClient; + fn blobscan_client(&self) -> &dyn CommonBlobscanClient; fn provider(&self) -> &Provider; } @@ -82,12 +82,12 @@ impl Context { } impl CommonContext for Context { - fn beacon_client(&self) -> &Box { - &self.inner.beacon_client + fn beacon_client(&self) -> &dyn CommonBeaconClient { + self.inner.beacon_client.as_ref() } - fn blobscan_client(&self) -> &Box { - &self.inner.blobscan_client + fn blobscan_client(&self) -> &dyn CommonBlobscanClient { + self.inner.blobscan_client.as_ref() } fn provider(&self) -> &Provider { @@ -127,12 +127,12 @@ impl Context { #[cfg(test)] impl CommonContext for Context { - fn beacon_client(&self) -> &Box { - &self.inner.beacon_client + fn beacon_client(&self) -> &dyn CommonBeaconClient { + self.inner.beacon_client.as_ref() } - fn blobscan_client(&self) -> &Box { - &self.inner.blobscan_client + fn blobscan_client(&self) -> &dyn CommonBlobscanClient { + self.inner.blobscan_client.as_ref() } fn provider(&self) -> &Provider { diff --git a/src/indexer/event_handlers/head.rs b/src/indexer/event_handlers/head.rs index 50de1be..4e81d77 100644 --- a/src/indexer/event_handlers/head.rs +++ b/src/indexer/event_handlers/head.rs @@ -701,6 +701,4 @@ mod tests { head_event } - - // Additional tests for error handling, etc. } diff --git a/src/slots_processor/mod.rs b/src/slots_processor/mod.rs index 5766213..259ab99 100644 --- a/src/slots_processor/mod.rs +++ b/src/slots_processor/mod.rs @@ -1,14 +1,11 @@ use anyhow::{anyhow, Context as AnyhowContext, Result}; -use ethers::{ - providers::{Http as HttpProvider, Middleware}, - types::H256, -}; +use ethers::providers::{Http as HttpProvider, Middleware}; use tracing::{debug, info}; use crate::{ clients::{ - beacon::types::{BlockHeader, BlockId}, + beacon::types::BlockId, blobscan::types::{Blob, Block, Transaction}, }, context::CommonContext, @@ -24,21 +21,6 @@ pub struct SlotsProcessor { context: Box>, } -#[derive(Debug, Clone)] -pub struct BlockData { - pub root: H256, - pub slot: u32, -} - -impl From for BlockData { - fn from(block_header: BlockHeader) -> Self { - Self { - root: block_header.root, - slot: block_header.header.message.slot, - } - } -} - impl SlotsProcessor { pub fn new(context: Box>) -> SlotsProcessor { Self { context }