Skip to content

Commit

Permalink
Change signature of try_preserving_privacy to return Vec<Outpoint>
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebear21 committed Jul 31, 2024
1 parent a122a5b commit b4aa5e8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion payjoin-cli/src/app/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn try_contributing_inputs(
.map(|i| (i.amount, OutPoint { txid: i.txid, vout: i.vout }))
.collect();

let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg");
let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg")[0];
let selected_utxo = available_inputs
.iter()
.find(|i| i.txid == selected_outpoint.txid && i.vout == selected_outpoint.vout)
Expand Down
2 changes: 1 addition & 1 deletion payjoin-cli/src/app/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn try_contributing_inputs(
.map(|i| (i.amount, OutPoint { txid: i.txid, vout: i.vout }))
.collect();

let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg");
let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg")[0];
let selected_utxo = available_inputs
.iter()
.find(|i| i.txid == selected_outpoint.txid && i.vout == selected_outpoint.vout)
Expand Down
17 changes: 8 additions & 9 deletions payjoin/src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl WantsInputs {
pub fn try_preserving_privacy(
&self,
candidate_inputs: HashMap<Amount, OutPoint>,
) -> Result<OutPoint, SelectionError> {
) -> Result<Vec<OutPoint>, SelectionError> {
if candidate_inputs.is_empty() {
return Err(SelectionError::from(InternalSelectionError::Empty));
}
Expand All @@ -446,7 +446,7 @@ impl WantsInputs {
fn avoid_uih(
&self,
candidate_inputs: HashMap<Amount, OutPoint>,
) -> Result<OutPoint, SelectionError> {
) -> Result<Vec<OutPoint>, SelectionError> {
let min_original_out_sats = self
.payjoin_psbt
.unsigned_tx
Expand All @@ -473,7 +473,7 @@ impl WantsInputs {
if candidate_min_in > candidate_min_out {
// The candidate avoids UIH2 but conforms to UIH1: Optimal change heuristic.
// It implies the smallest output is the sender's change address.
return Ok(candidate.1);
return Ok(vec![candidate.1]);
}
}

Expand All @@ -484,12 +484,11 @@ impl WantsInputs {
fn select_first_candidate(
&self,
candidate_inputs: HashMap<Amount, OutPoint>,
) -> Result<OutPoint, SelectionError> {
candidate_inputs
.values()
.next()
.cloned()
.ok_or_else(|| SelectionError::from(InternalSelectionError::NotFound))
) -> Result<Vec<OutPoint>, SelectionError> {
match candidate_inputs.values().next().cloned() {
Some(outpoint) => Ok(vec![outpoint]),
None => Err(SelectionError::from(InternalSelectionError::NotFound)),
}
}

pub fn contribute_witness_input(self, txo: TxOut, outpoint: OutPoint) -> ProvisionalProposal {
Expand Down
2 changes: 1 addition & 1 deletion payjoin/src/receive/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl WantsInputs {
pub fn try_preserving_privacy(
&self,
candidate_inputs: HashMap<Amount, OutPoint>,
) -> Result<OutPoint, SelectionError> {
) -> Result<Vec<OutPoint>, SelectionError> {
self.inner.try_preserving_privacy(candidate_inputs)
}

Expand Down
6 changes: 4 additions & 2 deletions payjoin/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ mod integration {
.map(|i| (i.amount, OutPoint { txid: i.txid, vout: i.vout }))
.collect();

let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg");
let selected_outpoint =
payjoin.try_preserving_privacy(candidate_inputs).expect("gg")[0];
let selected_utxo = available_inputs
.iter()
.find(|i| i.txid == selected_outpoint.txid && i.vout == selected_outpoint.vout)
Expand Down Expand Up @@ -763,7 +764,8 @@ mod integration {
.map(|i| (i.amount, OutPoint { txid: i.txid, vout: i.vout }))
.collect();

let selected_outpoint = payjoin.try_preserving_privacy(candidate_inputs).expect("gg");
let selected_outpoint =
payjoin.try_preserving_privacy(candidate_inputs).expect("gg")[0];
let selected_utxo = available_inputs
.iter()
.find(|i| i.txid == selected_outpoint.txid && i.vout == selected_outpoint.vout)
Expand Down

0 comments on commit b4aa5e8

Please sign in to comment.