Skip to content

Commit

Permalink
refactor: apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
PJColombo committed Feb 11, 2025
1 parent ee52483 commit 7ff8fec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
11 changes: 3 additions & 8 deletions src/clients/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ impl CommonBeaconClient for BeaconClient {
let path = format!("v2/beacon/blocks/{}", { block_id.to_detailed_string() });
let url = self.base_url.join(path.as_str())?;

json_get!(&self.client, url, BlockResponse, self.exp_backoff.clone()).map(|res| match res {
Some(r) => Some(r.into()),
None => None,
})
json_get!(&self.client, url, BlockResponse, self.exp_backoff.clone())
.map(|res| res.map(|r| r.into()))
}

async fn get_block_header(&self, block_id: BlockId) -> ClientResult<Option<BlockHeader>> {
Expand All @@ -77,10 +75,7 @@ impl CommonBeaconClient for BeaconClient {
BlockHeaderResponse,
self.exp_backoff.clone()
)
.map(|res| match res {
Some(r) => Some(r.into()),
None => None,
})
.map(|res| res.map(|r| r.into()))
}

async fn get_blobs(&self, block_id: BlockId) -> ClientResult<Option<Vec<Blob>>> {
Expand Down
2 changes: 1 addition & 1 deletion src/clients/beacon/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl BlockIdResolution for BlockId {
match self {
BlockId::Slot(slot) => Ok(*slot),
_ => match beacon_client
.get_block_header(self.clone().into())
.get_block_header(self.clone())
.await
.map_err(|err| BlockIdResolutionError::FailedBlockIdResolution {
block_id: self.clone(),
Expand Down
20 changes: 9 additions & 11 deletions src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,15 @@ impl Indexer<ReqwestTransport> {
},
};

let last_synced_block = sync_state
.map(|state| {
state
.last_upper_synced_slot
.map(|last_upper_synced_slot| BlockHeader {
slot: last_upper_synced_slot,
root: B256::ZERO,
parent_root: B256::ZERO,
})
})
.flatten();
let last_synced_block = sync_state.and_then(|state| {
state
.last_upper_synced_slot
.map(|last_upper_synced_slot| BlockHeader {
slot: last_upper_synced_slot,
root: B256::ZERO,
parent_root: B256::ZERO,
})
});

let upper_indexed_block_id = match &last_synced_block {

Check warning on line 124 in src/indexer/mod.rs

View workflow job for this annotation

GitHub Actions / Run tests

called `map(..).flatten()` on `Option`

warning: called `map(..).flatten()` on `Option` --> src/indexer/mod.rs:115:14 | 115 | .map(|state| { | ______________^ 116 | | state 117 | | .last_upper_synced_slot 118 | | .map(|last_upper_synced_slot| BlockHeader { ... | 123 | | }) 124 | | .flatten(); | |______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten = note: `#[warn(clippy::map_flatten)]` on by default help: try replacing `map` with `and_then` and remove the `.flatten()` | 115 ~ .and_then(|state| { 116 + state 117 + .last_upper_synced_slot 118 + .map(|last_upper_synced_slot| BlockHeader { 119 + slot: last_upper_synced_slot, 120 + root: B256::ZERO, 121 + parent_root: B256::ZERO, 122 + }) 123 ~ }); |
Some(block) => block.slot.into(),
Expand Down
13 changes: 5 additions & 8 deletions src/slots_processor/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ pub fn create_tx_hash_versioned_hashes_mapping(
let mut tx_to_versioned_hashes = HashMap::new();

if let Some(transactions) = block.transactions.as_transactions() {
transactions
.iter()
.for_each(|tx| match &tx.blob_versioned_hashes {
Some(versioned_hashes) => {
tx_to_versioned_hashes.insert(tx.hash, versioned_hashes.clone());
}
None => {}
});
transactions.iter().for_each(|tx| {
if let Some(versioned_hashes) = tx.blob_versioned_hashes.as_ref() {
tx_to_versioned_hashes.insert(tx.hash, versioned_hashes.clone());
}
});
}

Ok(tx_to_versioned_hashes)

Check warning on line 22 in src/slots_processor/helpers.rs

View workflow job for this annotation

GitHub Actions / Run tests

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/slots_processor/helpers.rs:17:28 | 17 | .for_each(|tx| match &tx.blob_versioned_hashes { | ____________________________^ 18 | | Some(versioned_hashes) => { 19 | | tx_to_versioned_hashes.insert(tx.hash, versioned_hashes.clone()); 20 | | } 21 | | None => {} 22 | | }); | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match = note: `#[warn(clippy::single_match)]` on by default help: try | 17 ~ .for_each(|tx| if let Some(versioned_hashes) = &tx.blob_versioned_hashes { 18 + tx_to_versioned_hashes.insert(tx.hash, versioned_hashes.clone()); 19 ~ }); |
Expand Down
2 changes: 1 addition & 1 deletion src/slots_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl SlotsProcessor<ReqwestTransport> {
reorg_depth += 1;
}

Err(anyhow!("No common block found").into())
Err(anyhow!("No common block found"))

Check warning on line 327 in src/slots_processor/mod.rs

View workflow job for this annotation

GitHub Actions / Run tests

useless conversion to the same type: `anyhow::Error`

warning: useless conversion to the same type: `anyhow::Error` --> src/slots_processor/mod.rs:327:13 | 327 | Err(anyhow!("No common block found").into()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `anyhow!("No common block found")` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
}

/// Returns the path of blocks with execution payload from the head block to the provided block.
Expand Down

0 comments on commit 7ff8fec

Please sign in to comment.