From 290e22bdf368cf2b6d062310ce53893cfa9dfdc4 Mon Sep 17 00:00:00 2001 From: Daniel Roberts Date: Sun, 14 Jan 2024 00:09:12 -0600 Subject: [PATCH] Fix clippy errors --- src/reserves.rs | 54 ++++++++++++++++++++------------------------- src/txout_set.rs | 3 +-- tests/regtestenv.rs | 1 + 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/reserves.rs b/src/reserves.rs index e0461c3..117c94f 100644 --- a/src/reserves.rs +++ b/src/reserves.rs @@ -227,18 +227,15 @@ impl ReserveProof for Transaction { let serialized_tx = serialize(&self); // Check that all inputs besides the challenge input are valid - prevouts - .iter() - .map(|(i, prevout)| { - bitcoinconsensus::verify( - prevout.script_pubkey.to_bytes().as_slice(), - prevout.value, - &serialized_tx, - *i, - ) - .map_err(|e| ProofError::SignatureValidation(*i, format!("{:?}", e))) - }) - .collect::>()?; + prevouts.iter().try_for_each(|(i, prevout)| { + bitcoinconsensus::verify( + prevout.script_pubkey.to_bytes().as_slice(), + prevout.value, + &serialized_tx, + *i, + ) + .map_err(|e| ProofError::SignatureValidation(*i, format!("{:?}", e))) + })?; // Check that all inputs besides the challenge input actually // commit to the challenge input by modifying the challenge @@ -257,23 +254,20 @@ impl ReserveProof for Transaction { serialize(&malleated_tx) }; - prevouts - .iter() - .map(|(i, prevout)| { - match bitcoinconsensus::verify( - prevout.script_pubkey.to_bytes().as_slice(), - prevout.value, - &serialized_malleated_tx, + prevouts.iter().try_for_each(|(i, prevout)| { + match bitcoinconsensus::verify( + prevout.script_pubkey.to_bytes().as_slice(), + prevout.value, + &serialized_malleated_tx, + *i, + ) { + Ok(_) => Err(ProofError::SignatureValidation( *i, - ) { - Ok(_) => Err(ProofError::SignatureValidation( - *i, - "Does not commit to challenge input".to_string(), - )), - Err(_) => Ok(()), - } - }) - .collect::>()?; + "Does not commit to challenge input".to_string(), + )), + Err(_) => Ok(()), + } + })?; Ok(sum) } @@ -724,7 +718,7 @@ mod test { use bdk::bitcoin::hashes::hex::FromHex; let tx = as FromHex>::from_hex(s).unwrap(); - deserialize(&mut tx.as_slice()).unwrap() + deserialize(tx.as_slice()).unwrap() } #[test] @@ -736,6 +730,6 @@ mod test { let message = "This belongs to me."; - tx.verify_reserve_proof(&message, &wallet).unwrap(); + tx.verify_reserve_proof(message, &wallet).unwrap(); } } diff --git a/src/txout_set.rs b/src/txout_set.rs index d6e05d9..7671ef5 100644 --- a/src/txout_set.rs +++ b/src/txout_set.rs @@ -141,8 +141,7 @@ where { let outpoints: Vec<_> = outpoints.into_iter().collect(); - let outpoint_set: BTreeSet<&OutPoint> = - outpoints.iter().map(|outpoint| *outpoint).collect(); + let outpoint_set: BTreeSet<&OutPoint> = outpoints.iter().copied().collect(); let tx_heights: BTreeMap<_, _> = if self.max_block_height < u32::MAX { outpoint_set diff --git a/tests/regtestenv.rs b/tests/regtestenv.rs index 6c14e31..746cc84 100644 --- a/tests/regtestenv.rs +++ b/tests/regtestenv.rs @@ -43,6 +43,7 @@ impl RegTestEnv { &self.electrsd.electrum_url } + #[allow(dead_code)] /// returns the URL where an esplora client can connect to the embedded esplora server pub fn esplora_url(&self) -> &Option { &self.electrsd.esplora_url