Skip to content

Commit

Permalink
style: resolve clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PJColombo committed Jun 19, 2024
1 parent e4febf9 commit 4c0762e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 55 deletions.
23 changes: 0 additions & 23 deletions src/clients/beacon/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,7 +16,6 @@ pub enum BlockId {
pub enum Topic {
Head,
FinalizedCheckpoint,
ChainReorg,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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<HeadEventData> for BlockData {
fn from(event_data: HeadEventData) -> Self {
Self {
root: event_data.block,
slot: event_data.slot,
}
}
}
20 changes: 10 additions & 10 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{
use crate::clients::{beacon::MockCommonBeaconClient, blobscan::MockCommonBlobscanClient};

pub trait CommonContext<T>: Send + Sync + Debug + DynClone {
fn beacon_client(&self) -> &Box<dyn CommonBeaconClient>;
fn blobscan_client(&self) -> &Box<dyn CommonBlobscanClient>;
fn beacon_client(&self) -> &dyn CommonBeaconClient;
fn blobscan_client(&self) -> &dyn CommonBlobscanClient;
fn provider(&self) -> &Provider<T>;
}

Expand Down Expand Up @@ -82,12 +82,12 @@ impl Context<HttpProvider> {
}

impl CommonContext<HttpProvider> for Context<HttpProvider> {
fn beacon_client(&self) -> &Box<dyn CommonBeaconClient> {
&self.inner.beacon_client
fn beacon_client(&self) -> &dyn CommonBeaconClient {
self.inner.beacon_client.as_ref()
}

fn blobscan_client(&self) -> &Box<dyn CommonBlobscanClient> {
&self.inner.blobscan_client
fn blobscan_client(&self) -> &dyn CommonBlobscanClient {
self.inner.blobscan_client.as_ref()
}

fn provider(&self) -> &Provider<HttpProvider> {
Expand Down Expand Up @@ -127,12 +127,12 @@ impl Context<MockProvider> {

#[cfg(test)]
impl CommonContext<MockProvider> for Context<MockProvider> {
fn beacon_client(&self) -> &Box<dyn CommonBeaconClient> {
&self.inner.beacon_client
fn beacon_client(&self) -> &dyn CommonBeaconClient {
self.inner.beacon_client.as_ref()
}

fn blobscan_client(&self) -> &Box<dyn CommonBlobscanClient> {
&self.inner.blobscan_client
fn blobscan_client(&self) -> &dyn CommonBlobscanClient {
self.inner.blobscan_client.as_ref()
}

fn provider(&self) -> &Provider<MockProvider> {
Expand Down
2 changes: 0 additions & 2 deletions src/indexer/event_handlers/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,4 @@ mod tests {

head_event
}

// Additional tests for error handling, etc.
}
22 changes: 2 additions & 20 deletions src/slots_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -24,21 +21,6 @@ pub struct SlotsProcessor<T> {
context: Box<dyn CommonContext<T>>,
}

#[derive(Debug, Clone)]
pub struct BlockData {
pub root: H256,
pub slot: u32,
}

impl From<BlockHeader> for BlockData {
fn from(block_header: BlockHeader) -> Self {
Self {
root: block_header.root,
slot: block_header.header.message.slot,
}
}
}

impl SlotsProcessor<HttpProvider> {
pub fn new(context: Box<dyn CommonContext<HttpProvider>>) -> SlotsProcessor<HttpProvider> {
Self { context }
Expand Down

0 comments on commit 4c0762e

Please sign in to comment.