Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Sep 19, 2023
1 parent ed11b76 commit 2ba7410
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
48 changes: 22 additions & 26 deletions src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use zksync_web3_decl::types::FilterChanges;
pub enum FilterType {
/// A filter for block information
Block(BlockFilter),
/// A filter for log information
Log(LogFilter),
/// A filter for log information.
/// This is [Box] to ensure the enum invariants are similar size.
Log(Box<LogFilter>),
/// A filter for pending transaction information
PendingTransaction(PendingTransactionFilter),
}
Expand Down Expand Up @@ -70,7 +71,7 @@ impl LogFilter {
}
}

matched_topic.iter().all(|m| *m == true)
matched_topic.iter().all(|m| *m)
}
}

Expand Down Expand Up @@ -121,13 +122,13 @@ impl EthFilters {
.ok_or("overflow")?;
self.filters.insert(
self.id_counter,
FilterType::Log(LogFilter {
FilterType::Log(Box::new(LogFilter {
from_block,
to_block,
addresses,
topics,
updates: Default::default(),
}),
})),
);

log::info!("created log filter '{:#x}'", self.id_counter);
Expand Down Expand Up @@ -198,36 +199,31 @@ impl EthFilters {

/// Notify available filters of a newly produced block
pub fn notify_new_block(&mut self, hash: H256) {
self.filters
.iter_mut()
.for_each(|(_, filter)| match filter {
FilterType::Block(f) => f.updates.push(hash),
_ => (),
})
self.filters.iter_mut().for_each(|(_, filter)| {
if let FilterType::Block(f) = filter {
f.updates.push(hash)
}
})
}

/// Notify available filters of a new pending transaction
pub fn notify_new_pending_transaction(&mut self, hash: H256) {
self.filters
.iter_mut()
.for_each(|(_, filter)| match filter {
FilterType::PendingTransaction(f) => f.updates.push(hash),
_ => (),
})
self.filters.iter_mut().for_each(|(_, filter)| {
if let FilterType::PendingTransaction(f) = filter {
f.updates.push(hash)
}
})
}

/// Notify available filters of a new transaction log
pub fn notify_new_log(&mut self, log: &Log, latest_block_number: U64) {
self.filters
.iter_mut()
.for_each(|(_, filter)| match filter {
FilterType::Log(f) => {
if f.matches(&log, latest_block_number) {
f.updates.push(log.clone());
}
self.filters.iter_mut().for_each(|(_, filter)| {
if let FilterType::Log(f) = filter {
if f.matches(log, latest_block_number) {
f.updates.push(log.clone());
}
_ => (),
})
}
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hardhat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> HardhatNamespaceT
Box::pin(async move {
match inner.write() {
Ok(mut inner) => {
let num_blocks = num_blocks.unwrap_or(U64::from(1));
let num_blocks = num_blocks.unwrap_or_else(|| U64::from(1));
let interval_ms = interval
.unwrap_or(U64::from(1))
.unwrap_or_else(|| U64::from(1))
.saturating_mul(1_000.into());
if num_blocks.is_zero() {
return Err(jsonrpc_core::Error::invalid_params(
Expand Down
3 changes: 1 addition & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,8 +2208,7 @@ impl<S: Send + Sync + 'static + ForkSource + std::fmt::Debug> EthNamespaceT for
.as_u64()
.min(1024)
// Can't be more than the total number of blocks
.min(reader.current_miniblock + 1)
.max(1);
.clamp(1, reader.current_miniblock + 1);

let mut base_fee_per_gas = vec![U256::from(L2_GAS_PRICE); block_count as usize];

Expand Down

0 comments on commit 2ba7410

Please sign in to comment.