Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 23 additions & 45 deletions ergo-lib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,64 +284,42 @@ impl TransactionHintsBag {

/// Replacing Hints for an input index
pub fn replace_hints_for_input(&mut self, index: usize, hints_bag: HintsBag) {
let public: Vec<Hint> = hints_bag
.hints
.clone()
// Separate secret commitments (CommitmentHint) from other hints
let (secret, public): (Vec<Hint>, Vec<Hint>) = hints_bag.hints
.into_iter()
.filter(|hint| matches!(hint, Hint::CommitmentHint(_)))
.collect();
let secret: Vec<Hint> = hints_bag
.hints
.into_iter()
.filter(|hint| matches!(hint, Hint::SecretProven(_)))
.collect();
.partition(|hint| matches!(hint, Hint::CommitmentHint(_)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all CommitmentHints are secret, only OwnCommitment is


self.secret_hints.insert(index, HintsBag { hints: secret });
self.public_hints.insert(index, HintsBag { hints: public });
}

/// Adding hints for a input index
pub fn add_hints_for_input(&mut self, index: usize, hints_bag: HintsBag) {
let mut public: Vec<Hint> = hints_bag
.hints
.clone()
.into_iter()
.filter(|hint| matches!(hint, Hint::CommitmentHint(_)))
.collect();
let mut secret: Vec<Hint> = hints_bag
.hints
let (secret, public): (Vec<Hint>, Vec<Hint>) = hints_bag.hints
.into_iter()
.filter(|hint| matches!(hint, Hint::SecretProven(_)))
.collect();
let secret_bag = HintsBag::empty();
let public_bag = HintsBag::empty();
let old_secret: &Vec<Hint> = &self.secret_hints.get(&index).unwrap_or(&secret_bag).hints;
for hint in old_secret {
secret.push(hint.clone());
}
.partition(|hint| matches!(hint, Hint::CommitmentHint(_)));

let old_public: &Vec<Hint> = &self.public_hints.get(&index).unwrap_or(&public_bag).hints;
for hint in old_public {
public.push(hint.clone());
}
self.secret_hints.insert(index, HintsBag { hints: secret });
self.public_hints.insert(index, HintsBag { hints: public });
// Get existing hints or empty bags
let empty_bag = HintsBag::empty();
let mut existing_secret = self.secret_hints.get(&index).unwrap_or(&empty_bag).hints.clone();
let mut existing_public = self.public_hints.get(&index).unwrap_or(&empty_bag).hints.clone();

// Combine with new hints
existing_secret.extend(secret);
existing_public.extend(public);

self.secret_hints.insert(index, HintsBag { hints: existing_secret });
self.public_hints.insert(index, HintsBag { hints: existing_public });
}

/// Outputting HintsBag corresponding for an index
pub fn all_hints_for_input(&self, index: usize) -> HintsBag {
let mut hints: Vec<Hint> = Vec::new();
let secret_bag = HintsBag::empty();
let public_bag = HintsBag::empty();
let secrets: &Vec<Hint> = &self.secret_hints.get(&index).unwrap_or(&secret_bag).hints;
for hint in secrets {
hints.push(hint.clone());
}
let public: &Vec<Hint> = &self.public_hints.get(&index).unwrap_or(&public_bag).hints;
for hint in public {
hints.push(hint.clone());
}
let hints_bag: HintsBag = HintsBag { hints };
hints_bag
let empty_bag = HintsBag::empty();
let mut all_hints = Vec::new();

all_hints.extend(self.secret_hints.get(&index).unwrap_or(&empty_bag).hints.clone());
all_hints.extend(self.public_hints.get(&index).unwrap_or(&empty_bag).hints.clone());

HintsBag { hints: all_hints }
}
}
Loading