Skip to content

Commit

Permalink
fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rex4539 committed Jan 22, 2025
1 parent 4017f95 commit a944440
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion integration-tests/tests/wallet_to_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ mod wallet_basic {
println!("\n\nStarting Mempool!\n");

recipient_client.clear_state().await;
let _ = zingolib::lightclient::LightClient::start_mempool_monitor(recipient_client.clone())
zingolib::lightclient::LightClient::start_mempool_monitor(recipient_client.clone())
.unwrap();
tokio::time::sleep(std::time::Duration::from_secs(5)).await;

Expand Down
4 changes: 2 additions & 2 deletions zaino-state/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl ZcashIndexer for FetchServiceSubscriber {
.fetcher
.get_address_balance(address_strings.valid_address_strings().map_err(|error| {
FetchServiceError::RpcError(RpcError {
code: error.code() as i32 as i64,
code: error.code() as i64,
message: "Invalid address provided".to_string(),
data: None,
})
Expand Down Expand Up @@ -480,7 +480,7 @@ impl ZcashIndexer for FetchServiceSubscriber {
.fetcher
.get_address_utxos(address_strings.valid_address_strings().map_err(|error| {
FetchServiceError::RpcError(RpcError {
code: error.code() as i32 as i64,
code: error.code() as i64,
message: "Invalid address provided".to_string(),
data: None,
})
Expand Down
6 changes: 3 additions & 3 deletions zaino-state/src/local_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ impl BlockCacheSubscriber {
self.non_finalised_state
.get_compact_block(hash_or_height)
.await
.map_err(|e| BlockCacheError::NonFinalisedStateError(e))
.map_err(BlockCacheError::NonFinalisedStateError)
} else {
match self.config.no_db {
// Fetch from finalised state.
false => self
.finalised_state
.get_compact_block(hash_or_height)
.await
.map_err(|e| BlockCacheError::FinalisedStateError(e)),
.map_err(BlockCacheError::FinalisedStateError),
// Fetch from Validator.
true => {
let (_, block) = fetch_block_from_node(&self.fetcher, hash_or_height).await?;
Expand All @@ -122,7 +122,7 @@ impl BlockCacheSubscriber {
self.non_finalised_state
.get_chain_height()
.await
.map_err(|e| BlockCacheError::NonFinalisedStateError(e))
.map_err(BlockCacheError::NonFinalisedStateError)
}

/// Returns the status of the [`BlockCache`]..
Expand Down
25 changes: 11 additions & 14 deletions zaino-state/src/local_cache/non_finalised_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl NonFinalisedState {
loop {
match non_finalised_state.fetcher.get_blockchain_info().await {
Ok(chain_info) => {
best_block_hash = chain_info.best_block_hash.clone();
best_block_hash = chain_info.best_block_hash;
non_finalised_state.status.store(StatusType::Ready.into());
break;
}
Expand All @@ -148,7 +148,7 @@ impl NonFinalisedState {

match non_finalised_state.fetcher.get_blockchain_info().await {
Ok(chain_info) => {
check_block_hash = chain_info.best_block_hash.clone();
check_block_hash = chain_info.best_block_hash;
}
Err(e) => {
non_finalised_state.update_status_and_notify(StatusType::RecoverableError);
Expand Down Expand Up @@ -198,7 +198,7 @@ impl NonFinalisedState {
///
/// Newly mined blocks are treated as a reorg at chain_height[-0].
async fn fill_from_reorg(&self) -> Result<(), NonFinalisedStateError> {
let mut reorg_height = self
let mut reorg_height = *self
.heights_to_hashes
.get_state()
.iter()
Expand All @@ -208,8 +208,7 @@ impl NonFinalisedState {
"Failed to find the maximum height in the non-finalised state.".to_string(),
)
})?
.key()
.clone();
.key();

let mut reorg_hash = self.heights_to_hashes.get(&reorg_height).ok_or_else(|| {
NonFinalisedStateError::MissingData(format!(
Expand Down Expand Up @@ -298,7 +297,7 @@ impl NonFinalisedState {
self.heights_to_hashes.remove(&Height(block_height), None);
}
} else {
let pop_height = self
let pop_height = *self
.heights_to_hashes
.get_state()
.iter()
Expand All @@ -309,8 +308,7 @@ impl NonFinalisedState {
.to_string(),
)
})?
.key()
.clone();
.key();
if let Some(hash) = self.heights_to_hashes.get(&pop_height) {
if let Some(block) = self.hashes_to_blocks.get(&hash) {
if self
Expand Down Expand Up @@ -421,36 +419,35 @@ impl NonFinalisedStateSubscriber {

self.hashes_to_blocks
.get(&hash)
.and_then(|block| Some(block.as_ref().clone()))
.map(|block| block.as_ref().clone())
.ok_or_else(|| {
NonFinalisedStateError::MissingData(format!("Block not found for hash: {}", hash))
})
}

/// Returns the height of the latest block in the non-finalised state.
pub async fn get_chain_height(&self) -> Result<Height, NonFinalisedStateError> {
let (height, _) = self
let (height, _) = *self
.heights_to_hashes
.get_filtered_state(&HashSet::new())
.iter()
.max_by_key(|(height, ..)| height.0)
.ok_or_else(|| {
NonFinalisedStateError::MissingData("Non-finalised state is empty.".into())
})?
.clone();
})?;

Ok(height)
}

///
/// Returns if the height or hash is present in the respective collection.
pub async fn conatins_hash_or_height(&self, hash_or_height: HashOrHeight) -> bool {
match hash_or_height {
HashOrHeight::Height(height) => self.heights_to_hashes.contains_key(&height),
HashOrHeight::Hash(hash) => self.hashes_to_blocks.contains_key(&hash),
}
}

/// Returns the status of the NonFinalisedState..
/// Returns the status of the NonFinalisedState.
pub fn status(&self) -> StatusType {
self.status.load().into()
}
Expand Down

0 comments on commit a944440

Please sign in to comment.