Skip to content

Commit

Permalink
fix: fix iterator misuse
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Mar 2, 2023
1 parent 6a6eeea commit 1c9d701
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl DbcBuilder {
.spent_proof_shares
.iter()
.map(|(public_key, shares)| {
SpentProof::try_from_proof_shares(*public_key, transaction_hash, shares.iter())
SpentProof::try_from_proof_shares(*public_key, transaction_hash, shares)
})
.chain(self.spent_proofs.iter().cloned().map(Ok))
.collect::<Result<_>>()?;
Expand Down
10 changes: 5 additions & 5 deletions src/spent_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::{Commitment, Error, Hash, PublicKey, PublicKeySet, Result, Signature, SignatureShare};

use std::cmp::Ordering;
use std::{cmp::Ordering, collections::HashSet};

use custom_debug::Debug;

Expand Down Expand Up @@ -186,19 +186,19 @@ pub struct SpentProof {

impl SpentProof {
/// Attempts to build a SpentProof by combining a given set of proof shares
pub fn try_from_proof_shares<'a>(
pub fn try_from_proof_shares(
public_key: PublicKey,
transaction_hash: Hash,
shares: impl Iterator<Item = &'a SpentProofShare>,
shares: &HashSet<SpentProofShare>,
) -> Result<Self> {
let mut peekable_shares = shares.peekable();
let mut peekable_shares = shares.iter().peekable();
let any_share = peekable_shares
.peek()
.cloned()
.ok_or(Error::MissingSpentProofShare(public_key))?;

let reason = any_share.reason();
if !peekable_shares.all(|s| s.reason() == reason) {
if !shares.iter().all(|s| s.reason() == reason) {
return Err(Error::SpentProofShareReasonMismatch(public_key));
}

Expand Down

0 comments on commit 1c9d701

Please sign in to comment.