Skip to content

Commit

Permalink
style: Happify clippy (rust v. 1.83)
Browse files Browse the repository at this point in the history
Co-authored-by: Alan Szepieniec <[email protected]>
  • Loading branch information
Sword-Smith and aszepieniec committed Jan 9, 2025
1 parent 783a817 commit 1b4cce4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/connect_to_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ async fn check_if_connection_is_allowed(
let cli_arguments = global_state_lock.cli();
let global_state = global_state_lock.lock_guard().await;
fn versions_are_compatible(own_version: &str, other_version: &str) -> bool {
let own_version = semver::Version::parse(own_version)
.expect("Must be able to parse own version string. Got: {own_version}");
let own_version = semver::Version::parse(own_version).unwrap_or_else(|_| {
panic!("Must be able to parse own version string. Got: {own_version}")
});
let other_version = match semver::Version::parse(other_version) {
Ok(version) => version,
Err(err) => {
Expand Down
5 changes: 4 additions & 1 deletion src/models/proof_abstractions/tasm/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ pub mod test {
};
file_as_string
.lines()
.map(|s| Url::parse(s).expect("Must be able to parse string '{s}' as URL"))
.map(|s| {
Url::parse(s)
.unwrap_or_else(|_| panic!("Must be able to parse string '{s}' as URL"))
})
.collect()
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,14 +1754,14 @@ mod global_state_tests {
"Historical information must be restored for premine TX"
);

for i in 1..=2 {
for (i, mutxo) in mutxos.iter().enumerate().skip(1).take((1..=2).count()) {
assert_eq!(
Some((
block1.hash(),
block1.header().timestamp,
block1.header().height
)),
mutxos[i].confirmed_in_block,
mutxo.confirmed_in_block,
"Historical information must be restored for composer TX, i={i}"
);
}
Expand Down
13 changes: 7 additions & 6 deletions src/models/state/wallet/address/encrypted_utxo_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ impl EncryptedUtxoNotification {
pub(crate) fn into_bech32m(self, network: Network) -> String {
let hrp = Self::get_hrp(network);
let message = self.into_message();
let payload = bincode::serialize(&message)
.expect("Serialization shouldn't fail. Message was: {message:?}");
let payload = payload.to_base32();
let payload = bincode::serialize(&message).unwrap_or_else(|e| {
panic!("Serialization shouldn't fail. Message was: {message:?}\nerror: {e}")
});
let payload_base_32 = payload.to_base32();
let variant = bech32::Variant::Bech32m;
bech32::encode(&hrp, payload, variant).expect(
"bech32 encoding shouldn't fail. Arguments were:\n\n{hrp}\n\n{payload:?}\n\n{variant:?}",
)
bech32::encode(&hrp, payload_base_32, variant).unwrap_or_else(|e| panic!(
"bech32 encoding shouldn't fail. Arguments were:\n\n{hrp}\n\n{payload:?}\n\n{variant:?}\n\nerror: {e}"
))
}

/// decodes from a bech32m string and verifies it matches `network`
Expand Down
18 changes: 15 additions & 3 deletions src/models/state/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,26 @@ impl WalletSecret {
let outgoing_randomness_file: PathBuf =
Self::wallet_outgoing_secrets_path(wallet_directory_path);
if !outgoing_randomness_file.exists() {
Self::create_empty_wallet_randomness_file(&outgoing_randomness_file).expect(
"Create file for outgoing randomness must succeed. Attempted to create file: {outgoing_randomness_file}",
Self::create_empty_wallet_randomness_file(&outgoing_randomness_file).unwrap_or_else(
|_| {
panic!(
"Create file for outgoing randomness must succeed. Attempted to create file: {}",
outgoing_randomness_file.to_string_lossy()
)
},
);
}

let incoming_randomness_file = Self::wallet_incoming_secrets_path(wallet_directory_path);
if !incoming_randomness_file.exists() {
Self::create_empty_wallet_randomness_file(&incoming_randomness_file).expect("Create file for outgoing randomness must succeed. Attempted to create file: {incoming_randomness_file}");
Self::create_empty_wallet_randomness_file(&incoming_randomness_file).unwrap_or_else(
|_| {
panic!(
"Create file for outgoing randomness must succeed. Attempted to create file: {}",
incoming_randomness_file.to_string_lossy()
)
},
);
}

// Sanity checks that files were actually created
Expand Down
3 changes: 1 addition & 2 deletions src/models/state/wallet/wallet_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,7 @@ mod tests {
// guesser-fee UTXOs will not be valid, so we cannot require that all
// four MUTXOs have valid MSMPs, since the two guesser-UTXOs were
// orphaned with block 1b.
for i in 0..=1 {
let mutxo = &final_mutxos[i];
for mutxo in final_mutxos.iter().take((0..=1).count()) {
let item = Tip5::hash(&mutxo.utxo);
let (mutxo_sync_block_digest, msmp) =
mutxo.get_latest_membership_proof_entry().unwrap();
Expand Down

0 comments on commit 1b4cce4

Please sign in to comment.