Skip to content

Commit f7e322c

Browse files
committed
fix: warnings about if statements that can be compacted
1 parent 573e569 commit f7e322c

File tree

8 files changed

+47
-45
lines changed

8 files changed

+47
-45
lines changed

mithril-aggregator/src/dependency_injection/builder/support/sqlite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ impl DependenciesBuilder {
5353
let _ = connection.execute("pragma analysis_limit=400; pragma optimize;");
5454
}
5555

56-
if let Some(pool) = &self.sqlite_connection_cardano_transaction_pool {
57-
if let Ok(connection) = pool.connection() {
58-
let _ = connection.execute("pragma analysis_limit=400; pragma optimize;");
59-
}
56+
if let Some(pool) = &self.sqlite_connection_cardano_transaction_pool
57+
&& let Ok(connection) = pool.connection()
58+
{
59+
let _ = connection.execute("pragma analysis_limit=400; pragma optimize;");
6060
}
6161
}
6262

mithril-aggregator/src/file_uploaders/cloud_uploader/api.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ impl CloudUploader {
4646
impl FileUploader for CloudUploader {
4747
async fn upload_without_retry(&self, file_path: &Path) -> StdResult<FileUri> {
4848
let remote_file_path = self.remote_folder.join(get_file_name(file_path)?);
49-
if !self.allow_overwrite {
50-
if let Some(file_uri) = self
49+
if !self.allow_overwrite
50+
&& let Some(file_uri) = self
5151
.cloud_backend_uploader
5252
.file_exists(&remote_file_path)
5353
.await
5454
.with_context(|| "checking if file exists in cloud")?
55-
{
56-
return Ok(file_uri);
57-
}
55+
{
56+
return Ok(file_uri);
5857
}
5958

6059
let file_uri = self

mithril-aggregator/src/services/certifier/buffered_certifier.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,15 @@ impl CertifierService for BufferedCertifierService {
131131
.create_open_message(signed_entity_type, protocol_message)
132132
.await;
133133

134-
if creation_result.is_ok() {
135-
if let Err(error) = self
134+
if creation_result.is_ok()
135+
&& let Err(error) = self
136136
.try_register_buffered_signatures_to_current_open_message(signed_entity_type)
137137
.await
138-
{
139-
warn!(self.logger, "Failed to register buffered signatures to the new open message";
140-
"signed_entity_type" => ?signed_entity_type,
141-
"error" => ?error
142-
);
143-
}
138+
{
139+
warn!(self.logger, "Failed to register buffered signatures to the new open message";
140+
"signed_entity_type" => ?signed_entity_type,
141+
"error" => ?error
142+
);
144143
}
145144

146145
creation_result

mithril-aggregator/src/tools/file_archiver/api.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ impl FileArchiver {
6969
let temporary_archive_path = parameters.temporary_archive_path();
7070

7171
let temporary_file_archive = self
72-
.create_and_verify_archive(&temporary_archive_path, appender, parameters.compression_algorithm)
72+
.create_and_verify_archive(
73+
&temporary_archive_path,
74+
appender,
75+
parameters.compression_algorithm,
76+
)
7377
.inspect_err(|_err| {
74-
if temporary_archive_path.exists() {
75-
if let Err(remove_error) = fs::remove_file(&temporary_archive_path) {
76-
warn!(
77-
self.logger, " > Post FileArchiver.archive failure, could not remove temporary archive";
78-
"archive_path" => temporary_archive_path.display(),
79-
"error" => remove_error
80-
);
81-
}
78+
if temporary_archive_path.exists()
79+
&& let Err(remove_error) = fs::remove_file(&temporary_archive_path)
80+
{
81+
warn!(
82+
self.logger,
83+
" > Post FileArchiver.archive failure, could not remove temporary archive";
84+
"archive_path" => temporary_archive_path.display(),
85+
"error" => remove_error
86+
);
8287
}
8388
})
8489
.with_context(|| {

mithril-client-cli/src/utils/archive_unpacker/zip_unpacker.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ impl ArchiveFormat for ZipUnpacker {
3232
format!("Could not create directory '{}'", outpath.display())
3333
})?;
3434
} else {
35-
if let Some(parent) = outpath.parent() {
36-
if !parent.exists() {
37-
fs::create_dir_all(parent).with_context(|| {
38-
format!("Could not create directory '{}'", parent.display())
39-
})?;
40-
}
35+
if let Some(parent) = outpath.parent()
36+
&& !parent.exists()
37+
{
38+
fs::create_dir_all(parent).with_context(|| {
39+
format!("Could not create directory '{}'", parent.display())
40+
})?;
4141
}
4242
let mut outfile = File::create(&outpath)
4343
.with_context(|| format!("Could not create file '{}'", outpath.display()))?;

mithril-client/src/certificate_client/verify.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ impl MithrilCertificateVerifier {
140140
.await?;
141141

142142
#[cfg(feature = "unstable")]
143-
if let Some(cache) = self.verifier_cache.as_ref() {
144-
if !certificate.is_genesis() {
145-
cache
146-
.store_validated_certificate(&certificate.hash, &certificate.previous_hash)
147-
.await?;
148-
}
143+
if let Some(cache) = self.verifier_cache.as_ref()
144+
&& !certificate.is_genesis()
145+
{
146+
cache
147+
.store_validated_certificate(&certificate.hash, &certificate.previous_hash)
148+
.await?;
149149
}
150150

151151
trace!(self.logger, "Certificate validated"; "hash" => &certificate.hash, "previous_hash" => &certificate.previous_hash);

mithril-common/src/certificate_chain/certificate_verifier.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ impl MithrilCertificateVerifier {
228228
if let Some(signed_epoch) = &certificate
229229
.protocol_message
230230
.get_message_part(&ProtocolMessagePartKey::CurrentEpoch)
231+
&& **signed_epoch == certificate.epoch.to_string()
231232
{
232-
if **signed_epoch == certificate.epoch.to_string() {
233-
return Ok(());
234-
}
233+
return Ok(());
235234
}
236235

237236
Err(anyhow!(CertificateVerifierError::CertificateEpochUnmatch))

mithril-common/src/crypto_helper/merkle_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ impl<K: MKMapKey, V: MKMapValue<K>, S: MKTreeStorer> MKMap<K, V, S> {
194194
let leaves_by_keys = self.group_leaves_by_keys(leaves);
195195
let mut sub_proofs = BTreeMap::<K, MKMapProof<K>>::default();
196196
for (key, sub_leaves) in leaves_by_keys {
197-
if let Some(value) = self.get(&key) {
198-
if let Some(proof) = value.compute_proof(&sub_leaves)? {
199-
sub_proofs.insert(key.to_owned(), proof);
200-
}
197+
if let Some(value) = self.get(&key)
198+
&& let Some(proof) = value.compute_proof(&sub_leaves)?
199+
{
200+
sub_proofs.insert(key.to_owned(), proof);
201201
}
202202
}
203203

0 commit comments

Comments
 (0)